- Add GET /api/backup/export and POST /api/backup/import endpoints for full data backup
- Add drag-and-drop reorder for goal steps with PUT /api/goals/{id}/steps/reorder
- Auto-assign sort_order on step creation (preserves creation order)
- Fix duplicate milestone rendering in goal detail page
- Add category management button in goal dialog
- Migrate database default from SQLite to PostgreSQL
- Fix router guard redirect loop for logged-in users on setup/login pages
- Fix ALTER TABLE ADD COLUMN crash on callable defaults (uuid.uuid4)
- Add auth status rate limiter and token version caching
- Update CLAUDE.md to reflect current architecture
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
# 硬编码配置
|
|
import os
|
|
import secrets
|
|
import logging
|
|
|
|
_logger = logging.getLogger("app.config")
|
|
|
|
# api 目录的绝对路径(基于本文件位置计算,不依赖工作目录)
|
|
_BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
# 数据库配置
|
|
DATABASE_URL = os.getenv(
|
|
"DATABASE_URL",
|
|
"postgresql://ToDoList:53N2PTSjMBPDy6zY@192.168.1.86:5432/ToDoList",
|
|
)
|
|
|
|
# WebUI 配置
|
|
WEBUI_PATH = os.path.join(_BASE_DIR, "webui")
|
|
|
|
# CORS 配置
|
|
CORS_ORIGINS = [
|
|
"http://localhost:5173",
|
|
"http://localhost:23994",
|
|
]
|
|
|
|
# 日志配置
|
|
LOG_LEVEL = "INFO"
|
|
LOG_DIR = os.path.join(_BASE_DIR, "logs")
|
|
|
|
# 分页配置
|
|
DEFAULT_PAGE_SIZE = 20
|
|
|
|
# 服务配置
|
|
HOST = "0.0.0.0"
|
|
PORT = 23994
|
|
|
|
|
|
# JWT 密钥(首次启动随机生成,持久化到文件)
|
|
def _load_jwt_secret() -> str:
|
|
secret_file = os.path.join(_BASE_DIR, "data", ".jwt_secret")
|
|
if os.path.exists(secret_file):
|
|
with open(secret_file) as f:
|
|
return f.read().strip()
|
|
secret = secrets.token_hex(32)
|
|
os.makedirs(os.path.dirname(secret_file), exist_ok=True)
|
|
with open(secret_file, "w") as f:
|
|
f.write(secret)
|
|
_logger.warning("已生成新的 JWT 密钥")
|
|
return secret
|
|
|
|
|
|
JWT_SECRET = _load_jwt_secret()
|
|
ACCESS_TOKEN_EXPIRE_MINUTES = 1440 # 24小时
|
|
ACCESS_TOKEN_EXPIRE_SECONDS = ACCESS_TOKEN_EXPIRE_MINUTES * 60 |