mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2025-12-06 06:51:36 +01:00
wip: http backend with callbacks
..currently all callbacks are executed non-async for testing ..they may be bugs with async downloads not correctly being waited for ..there may be problems with binding changing variables correctly
This commit is contained in:
@@ -7,14 +7,16 @@ def add_to_download_queue(url, path):
|
||||
|
||||
def add_to_task_queue(task):
|
||||
'''Add a callback to background execution queue'''
|
||||
print("Executing tasks", task)
|
||||
task()
|
||||
|
||||
def _download(url, path):
|
||||
|
||||
response = requests.get(url + path, stream=True)
|
||||
response = requests.get(url + "?path=" + path, stream=True)
|
||||
|
||||
# Check if the request was successful
|
||||
if response.status_code == 200:
|
||||
|
||||
# Save the file locally
|
||||
local_filename = os.path.join("./cache", path)
|
||||
|
||||
@@ -22,4 +24,8 @@ def _download(url, path):
|
||||
for chunk in response.iter_content(chunk_size=8192): # Download in chunks
|
||||
f.write(chunk)
|
||||
|
||||
print(f"File downloaded successfully as {local_filename}")
|
||||
print(f"File downloaded successfully as {local_filename}")
|
||||
|
||||
else:
|
||||
|
||||
raise AssertionError("Non-200 Response for:", url, path, response.status_code, response.text)
|
||||
Reference in New Issue
Block a user