diff --git a/backend/api/endpoints/settings.py b/backend/api/endpoints/settings.py index 83a0223..537cd6d 100644 --- a/backend/api/endpoints/settings.py +++ b/backend/api/endpoints/settings.py @@ -13,6 +13,11 @@ def restart_server(): # This works in Docker if a restart policy is set (e.g., restart: always) os.kill(os.getpid(), 15) # SIGTERM +@router.get("/check") +async def check_settings_health(): + """Debug endpoint to verify settings router is mounted.""" + return {"status": "ok", "message": "Settings router is active"} + @router.post("/update-ytdlp") async def update_ytdlp(background_tasks: BackgroundTasks): try: @@ -36,3 +41,24 @@ async def update_ytdlp(background_tasks: BackgroundTasks): except Exception as e: logger.error(f"Unexpected Error: {e}") raise HTTPException(status_code=500, detail=str(e)) + +@router.post("/update-spotdl") +async def update_spotdl(background_tasks: BackgroundTasks): + try: + logger.info("Starting spotdl update...") + process = subprocess.run( + [sys.executable, "-m", "pip", "install", "--upgrade", "spotdl"], + capture_output=True, + text=True, + check=True + ) + logger.info(f"Update Output: {process.stdout}") + + background_tasks.add_task(restart_server) + return {"status": "success", "message": "spotdl updated. Server restarting..."} + except subprocess.CalledProcessError as e: + logger.error(f"Update Failed: {e.stderr}") + raise HTTPException(status_code=500, detail=f"Update failed: {e.stderr}") + except Exception as e: + logger.error(f"Unexpected Error: {e}") + raise HTTPException(status_code=500, detail=str(e)) diff --git a/backend/main.py b/backend/main.py index b655c14..5e1f2dc 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,5 +1,4 @@ -from fastapi import FastAPI -from fastapi import FastAPI, APIRouter # Added APIRouter +from fastapi import FastAPI, APIRouter from fastapi.middleware.cors import CORSMiddleware from fastapi.staticfiles import StaticFiles from fastapi.responses import FileResponse diff --git a/frontend/components/SettingsModal.tsx b/frontend/components/SettingsModal.tsx index f579d03..0022ff9 100644 --- a/frontend/components/SettingsModal.tsx +++ b/frontend/components/SettingsModal.tsx @@ -15,18 +15,20 @@ export default function SettingsModal({ isOpen, onClose }: SettingsModalProps) { if (!isOpen) return null; - const handleUpdate = async () => { + const handleUpdate = async (module: 'ytdlp' | 'spotdl') => { setUpdating(true); setStatus({ type: null, message: "" }); try { - await api.post("/settings/update-ytdlp", {}); - setStatus({ type: "success", message: "Update successful! Server is restarting..." }); + const endpoint = module === 'ytdlp' ? "/settings/update-ytdlp" : "/settings/update-spotdl"; + await api.post(endpoint, {}); + setStatus({ type: "success", message: `${module} updated! Server is restarting...` }); // Reload page after a delay to reflect restart setTimeout(() => { window.location.reload(); }, 5000); } catch (e: any) { - setStatus({ type: "error", message: e.message || "Update failed" }); + console.error(e); // Debugging + setStatus({ type: "error", message: e.message || "Update failed. Check console." }); } finally { setUpdating(false); } @@ -43,14 +45,16 @@ export default function SettingsModal({ isOpen, onClose }: SettingsModalProps) {
-
-

Core Components

-

- Update the core playback library (yt-dlp) to the latest version to fix playback issues. -

+
+
+

Core Components

+

+ Update core libraries to fix playback or download issues. +

+
+ +
{status.message && (