Update function name and add batched & awaited dls

This commit is contained in:
JeremyStar™ 2024-02-10 17:31:30 +01:00
parent 40555114ae
commit 0b9baa8600

View file

@ -32,7 +32,7 @@ func generate_id() -> int:
logger.diag("Generated new download id " + str(id))
return id
func await_download(url: String, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Dictionary:
func awaited_download(url: String, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Dictionary:
logger.verb("Creating awaited download")
var id: int = create_download(url, method, headers, data)
start_download(id)
@ -42,6 +42,18 @@ func await_download(url: String, method: HTTPClient.Method = HTTPClient.Method.M
list_complete.erase(id)
return dldata
func batch_awaited_download(urls: PackedStringArray, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Array[Dictionary]:
logger.verb("Creating " + str(urls.size()) + " awaited download(s)")
var dldata: Array[Dictionary]
for url in urls:
var id: int = create_download(url, method, headers, data)
start_download(id)
logger.diag("Waiting for download " + str(id) + " to finish")
while !is_download_complete(id): await get_tree().create_timer(0.1, true).timeout
dldata.append(list_complete[id])
list_complete.erase(id)
return dldata
func create_download(url: String, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), body: String = "") -> int:
logger.verb("Creating new download\n-> URL: " + url + "\n-> Method: " + str(method) + "\nHeaders:\n" + str(headers) + "\nBody:\n" + body)
var id = generate_id()