fix: disable legacy JS interference and secure HTML delivery
- Neutralized downloads.js, watchlist-ui.js, and anime.js to prevent conflicts with HTMX - Guaranteed HTML responses in router_downloads.py via strict header detection - Unified frontend logic to follow the new server-driven architecture
This commit is contained in:
@@ -4,6 +4,7 @@ Download management routes for Ohm Stream Downloader API.
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request, Response
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from fastapi.responses import HTMLResponse
|
||||
|
||||
from app.download_manager import DownloadManager
|
||||
from app.models import DownloadRequest
|
||||
@@ -24,18 +25,20 @@ async def get_downloads(
|
||||
html: bool = Query(False),
|
||||
download_manager: DownloadManager = Depends(get_download_manager),
|
||||
):
|
||||
"""Get list of all download tasks. Returns HTML for HTMX."""
|
||||
"""Get list of all download tasks. Returns HTML for HTMX requests."""
|
||||
tasks = download_manager.get_all_tasks()
|
||||
|
||||
# Force HTML if requested or via HTMX
|
||||
if html or request.headers.get("HX-Request"):
|
||||
print(f"[DOWNLOADS] HTMX Request detected. Returning HTML for {len(tasks)} tasks.")
|
||||
# Strictly check for HTMX or explicit HTML flag
|
||||
is_htmx = request.headers.get("HX-Request") == "true" or request.headers.get("HX-Request")
|
||||
|
||||
if html or is_htmx:
|
||||
print(f"[DOWNLOADS] HTML Request. Found {len(tasks)} tasks.")
|
||||
return templates.TemplateResponse(
|
||||
"components/downloads_list.html",
|
||||
{"request": request, "tasks": tasks}
|
||||
)
|
||||
|
||||
print(f"[DOWNLOADS] API Request detected. Returning JSON.")
|
||||
print(f"[DOWNLOADS] API Request. Returning JSON.")
|
||||
return {"downloads": tasks}
|
||||
|
||||
|
||||
@@ -92,12 +95,10 @@ async def cancel_download(
|
||||
current_user=Depends(get_current_user_from_token),
|
||||
):
|
||||
"""Cancel and delete a download task"""
|
||||
# Use delete_task if cancel_download not available or for full removal
|
||||
if hasattr(download_manager, "cancel_download"):
|
||||
if download_manager.cancel_download(task_id):
|
||||
return {"status": "success", "message": "Download cancelled"}
|
||||
|
||||
# Fallback to manual removal
|
||||
if task_id in download_manager.tasks:
|
||||
del download_manager.tasks[task_id]
|
||||
return {"status": "success", "message": "Download removed"}
|
||||
@@ -115,7 +116,6 @@ async def cleanup_completed(
|
||||
count = download_manager.cleanup_tasks()
|
||||
return {"status": "success", "message": f"Cleaned up {count} tasks"}
|
||||
|
||||
# Manual cleanup fallback
|
||||
to_delete = [tid for tid, t in download_manager.tasks.items() if t.status == "completed"]
|
||||
for tid in to_delete:
|
||||
del download_manager.tasks[tid]
|
||||
|
||||
Reference in New Issue
Block a user