mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-23 17:17:31 -04:00
await previous request
This commit is contained in:
parent
8e1ab4c96c
commit
8efcf24dd0
1 changed files with 20 additions and 0 deletions
|
@ -24,12 +24,19 @@ func _ready() -> void:
|
|||
|
||||
func is_cached(url: String) -> bool:
|
||||
var save_path = DOWNLOAD_FOLDER + "/" + url.md5_text() + "." + url.get_file().get_extension()
|
||||
for request in download_requests:
|
||||
if request.save_path == save_path:
|
||||
return false
|
||||
|
||||
return FileAccess.file_exists(save_path)
|
||||
|
||||
|
||||
func download(url: String, timeout: float = 0) -> String:
|
||||
var save_path = DOWNLOAD_FOLDER + "/" + url.md5_text() + "." + url.get_file().get_extension()
|
||||
|
||||
if has_request(save_path):
|
||||
await request_completed(save_path)
|
||||
|
||||
if FileAccess.file_exists(save_path):
|
||||
await get_tree().process_frame
|
||||
return save_path
|
||||
|
@ -48,6 +55,9 @@ func download_shared_lib(url: String, gate_url: String) -> String:
|
|||
var dir = DOWNLOAD_FOLDER + "/" + gate_url.md5_text()
|
||||
var save_path = dir + "/" + url.get_file()
|
||||
|
||||
if has_request(save_path):
|
||||
await request_completed(save_path)
|
||||
|
||||
if FileAccess.file_exists(save_path):
|
||||
await get_tree().process_frame
|
||||
return dir
|
||||
|
@ -61,6 +71,16 @@ func download_shared_lib(url: String, gate_url: String) -> String:
|
|||
return ""
|
||||
|
||||
|
||||
func has_request(save_path: String) -> bool:
|
||||
return download_requests.any(func(request: DownloadRequest): return request.save_path == save_path)
|
||||
|
||||
|
||||
func request_completed(save_path: String) -> void:
|
||||
for request in download_requests:
|
||||
if request.save_path == save_path:
|
||||
await request.http.request_completed
|
||||
|
||||
|
||||
func create_request(url: String, save_path: String, timeout: float = 0) -> int:
|
||||
var http = HTTPRequest.new()
|
||||
http.download_file = save_path
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue