Feat: Add SpotDL update and debug check endpoint
This commit is contained in:
parent
74748ec86f
commit
c23395e225
3 changed files with 61 additions and 13 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
|||
</div>
|
||||
|
||||
<div className="space-y-6">
|
||||
<div className="bg-[#2a2a2a] p-4 rounded-lg">
|
||||
<h3 className="font-semibold mb-2">Core Components</h3>
|
||||
<p className="text-sm text-gray-400 mb-4">
|
||||
Update the core playback library (yt-dlp) to the latest version to fix playback issues.
|
||||
</p>
|
||||
<div className="bg-[#2a2a2a] p-4 rounded-lg flex flex-col gap-4">
|
||||
<div>
|
||||
<h3 className="font-semibold mb-2">Core Components</h3>
|
||||
<p className="text-sm text-gray-400 mb-2">
|
||||
Update core libraries to fix playback or download issues.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={handleUpdate}
|
||||
onClick={() => handleUpdate('ytdlp')}
|
||||
disabled={updating}
|
||||
className={`w-full py-3 rounded-lg font-medium flex items-center justify-center gap-2 transition ${updating ? "bg-blue-600/50 cursor-not-allowed" : "bg-blue-600 hover:bg-blue-500"
|
||||
}`}
|
||||
|
|
@ -58,7 +62,7 @@ export default function SettingsModal({ isOpen, onClose }: SettingsModalProps) {
|
|||
{updating ? (
|
||||
<>
|
||||
<RefreshCw className="animate-spin" size={18} />
|
||||
Updating...
|
||||
Updating yt-dlp...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
|
|
@ -67,6 +71,25 @@ export default function SettingsModal({ isOpen, onClose }: SettingsModalProps) {
|
|||
</>
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={() => handleUpdate('spotdl')}
|
||||
disabled={updating}
|
||||
className={`w-full py-3 rounded-lg font-medium flex items-center justify-center gap-2 transition ${updating ? "bg-green-600/50 cursor-not-allowed" : "bg-green-600 hover:bg-green-500"
|
||||
}`}
|
||||
>
|
||||
{updating ? (
|
||||
<>
|
||||
<RefreshCw className="animate-spin" size={18} />
|
||||
Updating spotdl...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<RefreshCw size={18} />
|
||||
Update spotdl (Latest)
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{status.message && (
|
||||
|
|
|
|||
Loading…
Reference in a new issue