feat: 实现已确认的登录、采集和任务导出
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
"""运行配置。秘密只从环境变量或 data 目录读取,不写进代码。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
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 database_url() -> str:
|
||||
return os.environ.get("DECOM_DATABASE_URL", f"sqlite+pysqlite:///{(DATA_DIR / 'decom.db').as_posix()}")
|
||||
|
||||
|
||||
def postgres_conninfo() -> str | None:
|
||||
url = database_url()
|
||||
if url.startswith("postgresql+psycopg://"):
|
||||
return "postgresql://" + url.removeprefix("postgresql+psycopg://")
|
||||
if url.startswith("postgresql://"):
|
||||
return url
|
||||
return None
|
||||
|
||||
|
||||
def inline_worker() -> bool:
|
||||
return os.environ.get("DECOM_INLINE_WORKER", "1") == "1"
|
||||
|
||||
|
||||
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", "")
|
||||
Reference in New Issue
Block a user