Template
v2.5.5: fix 404 after panel update
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
@@ -278,12 +279,33 @@ class UpdateManager:
|
||||
}
|
||||
|
||||
def _archive_urls(self, tag: str) -> list[str]:
|
||||
urls: list[str] = []
|
||||
api_base = api_latest_url().rsplit('/releases/latest', 1)[0]
|
||||
for endpoint in (f'{api_base}/releases/tags/{tag}', api_latest_url()):
|
||||
try:
|
||||
req = urllib.request.Request(
|
||||
endpoint,
|
||||
headers={'Accept': 'application/json', 'User-Agent': 'Amnezia-Web-Panel-Updater'},
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||
payload = json.loads(resp.read().decode('utf-8', errors='replace') or '{}')
|
||||
zipball = (payload.get('zipball_url') or '').strip()
|
||||
if zipball:
|
||||
urls.append(zipball)
|
||||
except Exception:
|
||||
pass
|
||||
base = repo_url()
|
||||
return [
|
||||
urls.extend([
|
||||
f'{base}/archive/{tag}.zip',
|
||||
f'{base}/archive/{tag.lstrip("v")}.zip',
|
||||
f'{api_latest_url().rsplit("/releases/latest", 1)[0]}/archive/{tag}.zip',
|
||||
]
|
||||
f'{api_base}/archive/{tag}.zip',
|
||||
])
|
||||
seen = set()
|
||||
ordered: list[str] = []
|
||||
for url in urls:
|
||||
if url and url not in seen:
|
||||
seen.add(url)
|
||||
ordered.append(url)
|
||||
return ordered
|
||||
|
||||
def _download_archive(self, tag: str, dest_path: str) -> None:
|
||||
last_err = 'unknown error'
|
||||
@@ -383,15 +405,26 @@ class UpdateManager:
|
||||
return {'status': 'error', 'message': hint, 'mode': mode}
|
||||
|
||||
@staticmethod
|
||||
def schedule_restart(delay_sec: float = 1.5) -> None:
|
||||
def schedule_restart(app_root: str, delay_sec: float = 1.5) -> None:
|
||||
def _restart():
|
||||
time.sleep(max(0.5, float(delay_sec)))
|
||||
argv = [sys.executable] + sys.argv
|
||||
cwd = os.path.abspath(app_root or os.getcwd())
|
||||
logger.info('Restarting panel after update: %s (cwd=%s)', argv, cwd)
|
||||
try:
|
||||
argv = [sys.executable] + sys.argv
|
||||
logger.info('Restarting panel after update: %s', argv)
|
||||
os.chdir(cwd)
|
||||
os.execv(sys.executable, argv)
|
||||
except Exception:
|
||||
logger.exception('Failed to restart after update; exiting')
|
||||
logger.exception('execv restart failed; trying subprocess fallback')
|
||||
try:
|
||||
subprocess.Popen(
|
||||
argv,
|
||||
cwd=cwd,
|
||||
close_fds=True,
|
||||
start_new_session=True,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception('Failed to restart after update')
|
||||
os._exit(0)
|
||||
|
||||
threading.Thread(target=_restart, name='panel-update-restart', daemon=False).start()
|
||||
|
||||
Reference in New Issue
Block a user