fix: web-based first-run setup — removes terminal input(), works under systemd
This commit is contained in:
@@ -54,6 +54,34 @@ async def logout(authorization: Optional[str] = Header(None)):
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@router.get("/setup")
|
||||
async def setup_page():
|
||||
from fastapi.responses import FileResponse
|
||||
from auth import has_users
|
||||
from pathlib import Path
|
||||
if has_users():
|
||||
from fastapi.responses import RedirectResponse
|
||||
return RedirectResponse("/")
|
||||
return FileResponse(str(Path(__file__).parent.parent / "frontend" / "setup.html"))
|
||||
|
||||
|
||||
@router.post("/setup")
|
||||
async def setup_post(body: dict):
|
||||
from auth import has_users, create_user
|
||||
from config import load as load_config
|
||||
if has_users():
|
||||
raise HTTPException(status_code=403, detail="Bereits eingerichtet")
|
||||
username = body.get("username", "").strip()
|
||||
password = body.get("password", "")
|
||||
if not username or len(password) < 6:
|
||||
raise HTTPException(status_code=400, detail="Ungültige Eingabe")
|
||||
cfg = load_config()
|
||||
default_dir = cfg["output"]["path"]
|
||||
output_dir = body.get("output_dir") or default_dir
|
||||
create_user(username, password, output_dir, is_admin=True)
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Protected endpoints
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user