2
0
Fork 0

Update to 2485edfd87d0bb37d844c0a2e07b9bdc95dd5d5a

This commit is contained in:
JeremyStar™ 2024-03-28 13:05:12 +01:00
parent eef006cda3
commit 961312e5ad
11 changed files with 25 additions and 24 deletions

View file

@ -14,6 +14,7 @@
# #
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
## Passes [code]origin[/code] for you. ## Passes [code]origin[/code] for you.
## ##
## Pretty much a wrapper around CORE's logging implementation. ## Pretty much a wrapper around CORE's logging implementation.

View file

@ -23,12 +23,12 @@ extends Node
class_name Core class_name Core
# Constants # Constants
## The release number ## The version number
const version_release: int = 1 const version_version: int = 1
## The release type ## The version type
const version_type: CoreTypes.VersionType = CoreTypes.VersionType.BETA const version_type: CoreTypes.VersionType = CoreTypes.VersionType.BETA
## The release type number. Resets on every new release and release type. ## The version type number. Resets on every new version and version type.
const version_typerelease: int = 3 const version_typerelease: int = 4
# Modules # Modules
## Use this to access CORE's logging implementation. ## Use this to access CORE's logging implementation.
@ -92,12 +92,12 @@ func initialize_modules() -> void:
edl.name = "EasyDownLoader" edl.name = "EasyDownLoader"
storage.name = "Storage" storage.name = "Storage"
# Set scripts # Set scripts
logger.set_script(ResourceLoader.load(basepath + "src/Logger.gd")) logger.set_script(ResourceLoader.load(basepath + "src/logger.gd"))
misc.set_script(ResourceLoader.load(basepath + "src/Misc.gd")) misc.set_script(ResourceLoader.load(basepath + "src/misc.gd"))
sms.set_script(ResourceLoader.load(basepath + "src/Sms.gd")) sms.set_script(ResourceLoader.load(basepath + "src/sms.gd"))
logui.set_script(ResourceLoader.load(basepath + "src/Logui.gd")) logui.set_script(ResourceLoader.load(basepath + "src/logui.gd"))
edl.set_script(ResourceLoader.load(basepath + "src/Edl.gd")) edl.set_script(ResourceLoader.load(basepath + "src/edl.gd"))
storage.set_script(ResourceLoader.load(basepath + "src/Storage.gd")) storage.set_script(ResourceLoader.load(basepath + "src/storage.gd"))
# Set reference to self # Set reference to self
logger.core = self logger.core = self
misc.core = self misc.core = self
@ -254,10 +254,10 @@ func is_devmode() -> bool:
## - [code]%headless%[/code]: Returns the headless mode status ## - [code]%headless%[/code]: Returns the headless mode status
func get_formatted_string(string: String) -> String: func get_formatted_string(string: String) -> String:
# Version strings # Version strings
string = string.replace("%release%", str(version_release)) string = string.replace("%version%", str(version_version))
string = string.replace("%release_type%", str(version_typerelease)) string = string.replace("%version_type%", str(version_typerelease))
var semantic_version: Array[int] = get_version_semantic() var semantic_version: Array[int] = get_version_semantic()
string = string.replace("%release_semantic%", str(semantic_version[0]) + "." + str(semantic_version[1]) + "." + str(semantic_version[2])) string = string.replace("%version_semantic%", str(semantic_version[0]) + "." + str(semantic_version[1]) + "." + str(semantic_version[2]))
match(version_type): match(version_type):
CoreTypes.VersionType.RELEASE: CoreTypes.VersionType.RELEASE:
string = string.replace("%type%", "Release") string = string.replace("%type%", "Release")
@ -293,7 +293,7 @@ func get_version_semantic() -> Array[int]:
CoreTypes.VersionType.RELEASECANDIDATE: version_type_int = 2 CoreTypes.VersionType.RELEASECANDIDATE: version_type_int = 2
CoreTypes.VersionType.BETA: version_type_int = 1 CoreTypes.VersionType.BETA: version_type_int = 1
CoreTypes.VersionType.ALPHA: version_type_int = 0 CoreTypes.VersionType.ALPHA: version_type_int = 0
return [version_release, version_type_int, version_typerelease] return [version_version, version_type_int, version_typerelease]
# Determines CORE's installation/base path # Determines CORE's installation/base path
## Determines CORE's installation/base path[br] ## Determines CORE's installation/base path[br]

View file

@ -30,10 +30,10 @@ func generate_id() -> int:
logger.diagf("Edl", "Generated new download id " + str(id)) logger.diagf("Edl", "Generated new download id " + str(id))
return id return id
func awaited_request(url: String, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Dictionary: func awaited_request(url: String, parse_utf8: bool, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Dictionary:
logger.verbf("Edl", "Creating awaited request") logger.verbf("Edl", "Creating awaited request")
var id: int = create_download(url, method, headers, data) var id: int = create_download(url, method, headers, data)
start_download(id) start_download(id, parse_utf8)
logger.diagf("Edl", "Waiting for request " + str(id) + " to finish") logger.diagf("Edl", "Waiting for request " + str(id) + " to finish")
while !is_download_complete(id): await get_tree().create_timer(0.1, true).timeout while !is_download_complete(id): await get_tree().create_timer(0.1, true).timeout
var dldata: Dictionary = list_complete[id] var dldata: Dictionary = list_complete[id]
@ -41,19 +41,19 @@ func awaited_request(url: String, method: HTTPClient.Method = HTTPClient.Method.
return dldata return dldata
func oneline_awaited_request(url: String, return_utf8: bool = true, ignore_http_code: bool = false, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Variant: func oneline_awaited_request(url: String, return_utf8: bool = true, ignore_http_code: bool = false, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Variant:
var dldata: Dictionary = await awaited_request(url, method, headers, data) var dldata: Dictionary = await awaited_request(url, return_utf8, method, headers, data)
if dldata["result"] != Error.OK: return null if dldata["result"] != Error.OK: return null
elif !ignore_http_code and dldata["http_code"] != 200: return null elif !ignore_http_code and dldata["http_code"] != 200: return null
else: else:
if return_utf8: return dldata["body_utf8"] if return_utf8: return dldata["body_utf8"]
else: return dldata["body"] else: return dldata["body"]
func batch_awaited_request(urls: PackedStringArray, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Array[Dictionary]: func batch_awaited_request(urls: PackedStringArray, parse_utf8: bool, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), data: String = "") -> Array[Dictionary]:
logger.verbf("Edl", "Creating " + str(urls.size()) + " awaited request(s)") logger.verbf("Edl", "Creating " + str(urls.size()) + " awaited request(s)")
var dldata: Array[Dictionary]= [] var dldata: Array[Dictionary]= []
for url in urls: for url in urls:
var id: int = create_download(url, method, headers, data) var id: int = create_download(url, method, headers, data)
start_download(id) start_download(id, parse_utf8)
logger.diagf("Edl", "Waiting for request " + str(id) + " to finish") logger.diagf("Edl", "Waiting for request " + str(id) + " to finish")
while !is_download_complete(id): await get_tree().create_timer(0.1, true).timeout while !is_download_complete(id): await get_tree().create_timer(0.1, true).timeout
dldata.append(list_complete[id]) dldata.append(list_complete[id])
@ -61,12 +61,12 @@ func batch_awaited_request(urls: PackedStringArray, method: HTTPClient.Method =
return dldata return dldata
func create_download(url: String, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), body: String = "") -> int: func create_download(url: String, method: HTTPClient.Method = HTTPClient.Method.METHOD_GET, headers: PackedStringArray = PackedStringArray([]), body: String = "") -> int:
logger.verbf("Edl", "Creating new request\n-> URL: " + url + "\n-> Method: " + str(method) + "\nHeaders:\n" + str(headers) + "\nBody:\n" + body) logger.verbf("Edl", "Creating new request\n-> URL: " + url + "\n-> Method: " + str(method) + "\nHeaders: " + str(headers.size()) + "\nBody size: " + str(body.length()) + " Characters")
var id = generate_id() var id = generate_id()
list_queue.merge({ id: { "url": url, "method": method, "headers": headers, "body": body } }) list_queue.merge({ id: { "url": url, "method": method, "headers": headers, "body": body } })
return id return id
func start_download(id) -> void: func start_download(id: int, parse_utf8: bool) -> void:
logger.verbf("Edl", "Starting request " + str(id)) logger.verbf("Edl", "Starting request " + str(id))
list_active.merge({ id: list_queue[id] }) list_active.merge({ id: list_queue[id] })
list_queue.erase(id) list_queue.erase(id)
@ -76,8 +76,8 @@ func start_download(id) -> void:
download.accept_gzip = true download.accept_gzip = true
download.use_threads = true download.use_threads = true
var lambda: Callable = func(result: int, http_code: int, headers: PackedStringArray, body: PackedByteArray) -> void: var lambda: Callable = func(result: int, http_code: int, headers: PackedStringArray, body: PackedByteArray) -> void:
logger.verbf("Edl", "Request " + str(id) + " completed\nResult: " + str(result) + "\nHTTP response code: " + str(http_code) + "\nHeaders:\n" + str(headers) + "\nBody size: " + str(body.size()) + " Bytes // " + str(core.misc.byte2mib(body.size(), true)) + " MiB") logger.verbf("Edl", "Request " + str(id) + " completed\nResult: " + str(result) + "\nHTTP response code: " + str(http_code) + "\nHeaders: " + str(headers.size()) + "\nBody size: " + str(body.size()) + " Bytes // " + str(core.misc.byte2mib(body.size(), true)) + " MiB")
list_complete.merge({ id: { "result": result, "http_code": http_code, "headers": headers, "body": body, "body_utf8": body.get_string_from_utf8() } }) list_complete.merge({ id: { "result": result, "http_code": http_code, "headers": headers, "body": body, "body_utf8": body.get_string_from_utf8() if !parse_utf8 else "" } })
list_active.erase(id) list_active.erase(id)
download.connect("request_completed", lambda) download.connect("request_completed", lambda)
add_child(download) add_child(download)