Archived
Add watchlist backup import export
This commit is contained in:
@@ -58,6 +58,7 @@ class HandlerContext:
|
||||
download_watchlist_item: object
|
||||
ensure_runtime: object
|
||||
episode_list: object
|
||||
export_watchlist_backup: object
|
||||
get_config_snapshot: object
|
||||
get_jellyfin_sync_status: object
|
||||
get_watchlist_homepage_summary: object
|
||||
@@ -65,6 +66,7 @@ class HandlerContext:
|
||||
get_watchlist_refresh_status: object
|
||||
http_error: object
|
||||
index_html: str
|
||||
import_watchlist_backup: object
|
||||
queue_html: str
|
||||
reconcile_watchlist_downloaded_files: object
|
||||
remove_from_watchlist: object
|
||||
@@ -747,6 +749,12 @@ class Handler(BaseHTTPRequestHandler):
|
||||
elif parsed.path == "/api/config/jellyfin/sync-status":
|
||||
Handler._runtime(self)
|
||||
self.json(Handler._context(self).get_jellyfin_sync_status())
|
||||
elif parsed.path == "/api/config/watchlist/export":
|
||||
Handler._runtime(self)
|
||||
self.json_attachment(
|
||||
Handler._context(self).export_watchlist_backup(),
|
||||
"ani-cli-web-watchlist-backup.json",
|
||||
)
|
||||
else:
|
||||
self.error(HTTPStatus.NOT_FOUND, "Not found")
|
||||
except Exception as exc:
|
||||
@@ -796,6 +804,9 @@ class Handler(BaseHTTPRequestHandler):
|
||||
if str(merged.get("download_dir") or "").strip():
|
||||
Handler.validate_remote_path(self, merged["download_dir"], "download directory")
|
||||
self.json(Handler._context(self).reconcile_watchlist_downloaded_files(merged))
|
||||
elif parsed.path == "/api/config/watchlist/import":
|
||||
payload = Handler.require_json_object(self, self.body_json())
|
||||
self.json(Handler._context(self).import_watchlist_backup(payload))
|
||||
elif parsed.path == "/api/config/webhook/test":
|
||||
payload = Handler.require_json_object(self, self.body_json())
|
||||
validate_discord_webhook_url(payload.get("discord_webhook_url"))
|
||||
@@ -1014,6 +1025,19 @@ class Handler(BaseHTTPRequestHandler):
|
||||
data = json.dumps(payload).encode("utf-8")
|
||||
self.write_response_bytes(data, status, {"Content-Type": "application/json"})
|
||||
|
||||
def json_attachment(self, payload, filename, status=HTTPStatus.OK):
|
||||
data = json.dumps(payload, indent=2, sort_keys=True).encode("utf-8")
|
||||
safe_filename = str(filename or "watchlist-backup.json").replace('"', "")
|
||||
self.write_response_bytes(
|
||||
data,
|
||||
status,
|
||||
{
|
||||
"Content-Type": "application/json",
|
||||
"Content-Disposition": f'attachment; filename="{safe_filename}"',
|
||||
"Cache-Control": "no-store",
|
||||
},
|
||||
)
|
||||
|
||||
def write_response_bytes(self, payload, status, headers):
|
||||
try:
|
||||
self.send_response(status)
|
||||
|
||||
Reference in New Issue
Block a user