await previous request

This commit is contained in:
Nordup 2024-10-08 04:54:03 +04:00
parent 8e1ab4c96c
commit 8efcf24dd0

View file

@ -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