Skip to content

Commit

Permalink
fix: enhance error handling for file downloads in downloader and upda…
Browse files Browse the repository at this point in the history
…ter scripts
  • Loading branch information
lunamidori5 committed Feb 21, 2025
1 parent 541e622 commit 1dde06d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Webserver/Programs/Downloader/helper_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ async def acquire_files_with_streaming(FILES):
try:
response = requests.get(FILES, headers={"Discord-ID": random_id, "username": f"{str(username)}", "key": str(await get_api_key())}, stream=True, timeout=55)
response.raise_for_status()

if response.status_code != 200:
raise RuntimeError(f"Download failed: Server returned status code {response.status_code}")

total_size = int(response.headers.get("Content-Length", 0))

Expand Down
19 changes: 13 additions & 6 deletions Webserver/Programs/Updater/midori_ai_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@
os.makedirs(temp_folder_path, exist_ok=True)
os.chdir(temp_folder_path)

# Download new programs
for program in program_to_update:
spinner.start(text=f"Downloading program: {program[0]}")
response = requests.get("https://tea-cup.midori-ai.xyz/download/" + program[1], stream=True, timeout=55)
if response.status_code == 200:
with open(program[1], 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response
else:
spinner.fail(text=f"Error downloading {program[0]}: HTTP status code {response.status_code}")
exit(10)

# Remove existing programs
for program in program_to_update:
if "midori_ai_updater" in program[0]:
Expand All @@ -76,13 +88,8 @@
spinner.start(text=f"Removing existing program: {program[0]}")
os.remove(path)

# Download and install new programs
# install new programs
for program in program_to_update:
response = requests.get("https://tea-cup.midori-ai.xyz/download/" + program[1], stream=True, timeout=55)
with open(program[1], 'wb') as out_file:
spinner.start(text=f"Downloading program: {program[0]}")
shutil.copyfileobj(response.raw, out_file)
del response

os.chmod(program[1], 0o755)
spinner.start(text=f"Installing program: {program[0]}")
Expand Down

0 comments on commit 1dde06d

Please sign in to comment.