feat: 用安装页和编排完成部署,并整理登录页
This commit is contained in:
+39
-26
@@ -1,21 +1,41 @@
|
||||
"""运行配置。秘密只从环境变量或 data 目录读取,不写进代码。"""
|
||||
"""运行配置。连接信息在安装后写入 data/install.json,其余配置保存在数据库。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import secrets
|
||||
from pathlib import Path
|
||||
|
||||
BACKEND_ROOT = Path(__file__).resolve().parents[1]
|
||||
DATA_DIR = BACKEND_ROOT / "data"
|
||||
RESULT_DIR = DATA_DIR / "results"
|
||||
|
||||
|
||||
def data_dir() -> Path:
|
||||
override = os.environ.get("DECOM_DATA_DIR", "").strip()
|
||||
if override:
|
||||
return Path(override)
|
||||
return BACKEND_ROOT / "data"
|
||||
|
||||
|
||||
def result_dir() -> Path:
|
||||
return data_dir() / "results"
|
||||
|
||||
|
||||
def install_file() -> Path:
|
||||
return data_dir() / "install.json"
|
||||
|
||||
|
||||
def installed() -> bool:
|
||||
return install_file().is_file()
|
||||
|
||||
|
||||
def database_url() -> str:
|
||||
return os.environ.get("DECOM_DATABASE_URL", f"sqlite+pysqlite:///{(DATA_DIR / 'decom.db').as_posix()}")
|
||||
payload = json.loads(install_file().read_text(encoding="utf-8"))
|
||||
return str(payload["databaseUrl"])
|
||||
|
||||
|
||||
def postgres_conninfo() -> str | None:
|
||||
if not installed():
|
||||
return None
|
||||
url = database_url()
|
||||
if url.startswith("postgresql+psycopg://"):
|
||||
return "postgresql://" + url.removeprefix("postgresql+psycopg://")
|
||||
@@ -25,25 +45,18 @@ def postgres_conninfo() -> str | None:
|
||||
|
||||
|
||||
def inline_worker() -> bool:
|
||||
return os.environ.get("DECOM_INLINE_WORKER", "1") == "1"
|
||||
forced = os.environ.get("DECOM_INLINE_WORKER", "").strip()
|
||||
if forced == "1":
|
||||
return True
|
||||
if forced == "0":
|
||||
return False
|
||||
if not installed():
|
||||
return False
|
||||
from app.db import session_scope
|
||||
from app.models import AppSetting
|
||||
|
||||
|
||||
def jwt_secret() -> str:
|
||||
configured = os.environ.get("DECOM_JWT_SECRET", "").strip()
|
||||
if configured:
|
||||
return configured
|
||||
path = DATA_DIR / "jwt.secret"
|
||||
if path.is_file():
|
||||
return path.read_text(encoding="utf-8").strip()
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
value = secrets.token_hex(32)
|
||||
path.write_text(value, encoding="utf-8")
|
||||
return value
|
||||
|
||||
|
||||
def admin_username() -> str:
|
||||
return os.environ.get("DECOM_ADMIN_USERNAME", "").strip()
|
||||
|
||||
|
||||
def admin_password() -> str:
|
||||
return os.environ.get("DECOM_ADMIN_PASSWORD", "")
|
||||
with session_scope() as session:
|
||||
setting = session.get(AppSetting, 1)
|
||||
if setting is None:
|
||||
return False
|
||||
return bool(setting.inline_worker)
|
||||
|
||||
Reference in New Issue
Block a user