feat: 用安装页和编排完成部署,并整理登录页
This commit is contained in:
+26
-2
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import os
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi.responses import Response
|
||||
@@ -8,7 +9,8 @@ from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import Actor, current_actor, require_admin
|
||||
from app.config import RESULT_DIR
|
||||
from app.config import installed, result_dir
|
||||
from app.install import InstallError, perform_install
|
||||
from app.db import get_session, session_scope
|
||||
from app.models import AppSetting, CollectionSource, ExportTask, NqiAccount, User, utcnow
|
||||
from app.nqi.client import NqiAuthError, NqiClient, NqiError
|
||||
@@ -19,6 +21,28 @@ from app.tasks.runner import check_period, check_refresh, enqueue_export
|
||||
router = APIRouter(prefix="/api")
|
||||
|
||||
|
||||
@router.get("/install/status")
|
||||
def install_status() -> dict:
|
||||
return {
|
||||
"installed": installed(),
|
||||
"defaults": {
|
||||
"host": os.environ.get("DECOM_DB_HOST", "127.0.0.1"),
|
||||
"port": int(os.environ.get("DECOM_DB_PORT", "5432")),
|
||||
"database": os.environ.get("DECOM_DB_NAME", "decom"),
|
||||
"username": os.environ.get("DECOM_DB_USER", "postgres"),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@router.post("/install")
|
||||
def install(body: dict) -> dict:
|
||||
try:
|
||||
perform_install(body)
|
||||
except InstallError as exc:
|
||||
raise _bad(str(exc)) from exc
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
def _bad(message: str, status: int = 400) -> HTTPException:
|
||||
return HTTPException(status_code=status, detail=message)
|
||||
|
||||
@@ -246,7 +270,7 @@ def download_task(task_id: int, actor: Actor = Depends(current_actor), session:
|
||||
task = session.get(ExportTask, task_id)
|
||||
if task is None or task.owner_kind != actor.kind or task.owner_id != actor.id or task.status != "done":
|
||||
raise _bad("结果还不能下载", 404)
|
||||
path = RESULT_DIR / task.result_name
|
||||
path = result_dir() / task.result_name
|
||||
if not path.is_file():
|
||||
raise _bad("结果还不能下载", 404)
|
||||
return Response(content=path.read_bytes(), media_type="application/octet-stream", headers={"Content-Disposition": f'attachment; filename="{task.result_name}"'})
|
||||
|
||||
Reference in New Issue
Block a user