refactor: 移除旧版单文件管理后台兼容

This commit is contained in:
2026-07-15 07:46:30 +00:00
parent 4df439b5ce
commit 0b71e8d024
17 changed files with 16 additions and 2744 deletions
-2
View File
@@ -234,8 +234,6 @@ def change_password(
body: ChangePasswordRequest,
principal: AdminPrincipal = Depends(require_permission("admin:access")),
):
if principal.auth_type == "legacy_token":
raise HTTPException(status_code=400, detail="兼容令牌登录不能修改用户密码,请使用用户名密码登录")
new_password = body.new_password.strip()
if len(new_password) < 8:
raise HTTPException(status_code=400, detail="新密码至少需要 8 个字符")
+3 -3
View File
@@ -66,16 +66,16 @@ def normalize_install_root(value: str, fallback: str = "..") -> str:
def admin_change_token(body: ChangeAdminTokenRequest, auth=Depends(require_permission("admin:manage"))):
new_token = body.new_token.strip()
if len(new_token) < 8:
raise HTTPException(status_code=400, detail="兼容令牌至少需要 8 个字符")
raise HTTPException(status_code=400, detail="服务端兜底令牌至少需要 8 个字符")
if len(new_token) > 128:
raise HTTPException(status_code=400, detail="兼容令牌不能超过 128 个字符")
raise HTTPException(status_code=400, detail="服务端兜底令牌不能超过 128 个字符")
try:
persist_env_value(ENV_FILE_PATH, "ADMIN_TOKEN", new_token)
except Exception as exc:
raise HTTPException(status_code=500, detail=f"令牌已通过校验,但写入 .env 失败: {exc}")
set_admin_token(new_token)
os.environ["ADMIN_TOKEN"] = new_token
return {"code": 0, "msg": f"兼容管理员令牌已更新,并已写入 {ENV_FILE_PATH}"}
return {"code": 0, "msg": f"服务端兜底令牌已更新,并已写入 {ENV_FILE_PATH}"}
@router.get("/admin/runtime-config")
+3 -14
View File
@@ -7,7 +7,6 @@ from app.core.config import configured_path
router = APIRouter(include_in_schema=False)
ADMIN_HTML_PATH = configured_path("ADMIN_HTML_PATH", "legacy/admin.html")
ADMIN_UI_DIST_PATH = configured_path("ADMIN_UI_DIST_PATH", "admin-ui/dist")
ADMIN_UI_INDEX_PATH = ADMIN_UI_DIST_PATH / "index.html"
ADMIN_UI_ASSETS_PATH = ADMIN_UI_DIST_PATH / "assets"
@@ -23,20 +22,10 @@ def mount_admin_assets(app: FastAPI):
@router.get("/")
@router.get("/admin.html")
def admin_page():
if ADMIN_UI_INDEX_PATH.is_file():
return FileResponse(ADMIN_UI_INDEX_PATH, headers={"Cache-Control": "no-store"})
if not ADMIN_HTML_PATH.is_file():
raise HTTPException(status_code=404, detail="管理页面文件不存在")
return FileResponse(ADMIN_HTML_PATH, headers={"Cache-Control": "no-store"})
@router.get("/legacy-admin.html")
def legacy_admin_page():
if not ADMIN_HTML_PATH.is_file():
raise HTTPException(status_code=404, detail="旧管理页面文件不存在")
return FileResponse(ADMIN_HTML_PATH, headers={"Cache-Control": "no-store"})
if not ADMIN_UI_INDEX_PATH.is_file():
raise HTTPException(status_code=404, detail="管理后台前端文件不存在,请先构建 admin-ui/dist")
return FileResponse(ADMIN_UI_INDEX_PATH, headers={"Cache-Control": "no-store"})
@router.get("/favicon.ico")