5601de3d44
Vendored htmx.min.js (1.9.12) and alpine.min.js (3.14.1) into static/ -- self-hosted per the no-CDN/CSP requirement, included in base.html. routers/playlists.py: list/add/remove playlists, a detail page showing live per-playlist status via status_service (Spotify vs. beets vs. sldl index vs. quarantine), edit form for active/cron_expr/no_m3u/notes, and a "Run now" button wired to the jobs run-now endpoint. routers/credentials.py: write-only credential forms per scope (a saved secret is never sent back to the browser -- fields just show "(set)" and leaving a field blank keeps its current value, matching credential_service.set_credentials' partial-update semantics). routers/jobs.py: maintenance job list with run-now/enable-disable, and a recent-runs table that auto-refreshes via HTMX polling (hx-trigger="every 5s") against a partial-only endpoint -- the one place in the UI where avoiding a full-page reload actually matters, since job status changes while the page is sitting open. Per-run log viewing. Dashboard now shows real data (beets stats, playlist counts, recent job runs) instead of the placeholder from Task 2. Verified all 10 authenticated pages render successfully (200, no template errors) via TestClient with require_auth overridden, including the playlist detail page's graceful-degradation path when Spotify credentials aren't configured yet (renders a "couldn't fetch live status" message instead of a 500).
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, Request
|
|
from fastapi.responses import RedirectResponse
|
|
from fastapi.templating import Jinja2Templates
|
|
|
|
from app.db import get_db
|
|
from app.security.deps import require_auth
|
|
from app.services import credential_service
|
|
|
|
router = APIRouter(prefix="/settings/credentials", tags=["credentials"])
|
|
templates = Jinja2Templates(directory="app/templates")
|
|
|
|
|
|
@router.get("")
|
|
async def credentials_index(request: Request, user: dict = Depends(require_auth), db=Depends(get_db)):
|
|
# Write-only by design: never send a previously-saved secret value back
|
|
# to the browser. Each scope just reports which fields are already set.
|
|
configured = {
|
|
scope: set(credential_service.get_scope(db, scope).keys())
|
|
for scope in credential_service.SCOPE_FIELDS
|
|
}
|
|
return templates.TemplateResponse(
|
|
request,
|
|
"credentials/index.html",
|
|
{"scope_fields": credential_service.SCOPE_FIELDS, "configured": configured},
|
|
)
|
|
|
|
|
|
@router.post("/{scope}")
|
|
async def save_credentials(
|
|
scope: str, request: Request, user: dict = Depends(require_auth), db=Depends(get_db)
|
|
):
|
|
if scope not in credential_service.SCOPE_FIELDS:
|
|
raise HTTPException(404, "unknown credential scope")
|
|
form = await request.form()
|
|
values = {
|
|
field: value
|
|
for field, value in form.items()
|
|
if field in credential_service.SCOPE_FIELDS[scope] and value != ""
|
|
}
|
|
credential_service.set_credentials(db, scope, values)
|
|
return RedirectResponse(url="/settings/credentials", status_code=303)
|