feat: 增加运行日志(不记录敏感信息) - 启动摘要:端口/间隔/重试/超时/并发/Telegram 状态/内置平台/账号数/数据库路径 - 检查结果:成功余额、认证失败禁用、失败原因 - 提醒状态机:触发提醒/余额恢复 - API 操作:登录、平台/账号增删改、设置修改、密码修改 - Telegram 发送成功、请求耗时(DEBUG) - 全部日志不含 apikey/token/密码
This commit is contained in:
+10
@@ -118,9 +118,11 @@ def create_app(cfg: Config | None = None) -> FastAPI:
|
||||
def login(body: LoginRequest):
|
||||
import time
|
||||
if body.password != cfg.password:
|
||||
logger.warning("登录失败:密码错误")
|
||||
raise HTTPException(status_code=401, detail="密码错误")
|
||||
token = secrets.token_urlsafe(32)
|
||||
_tokens[token] = time.time() + TOKEN_TTL
|
||||
logger.info("登录成功")
|
||||
return {"token": token}
|
||||
|
||||
@app.post("/api/logout")
|
||||
@@ -172,6 +174,7 @@ def create_app(cfg: Config | None = None) -> FastAPI:
|
||||
if "UNIQUE" in str(exc):
|
||||
raise HTTPException(status_code=409, detail="平台名称已存在")
|
||||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
logger.info("创建平台: %s (id=%s, provider=%s)", body.name, pid, body.provider_id)
|
||||
return {"id": pid}
|
||||
|
||||
@app.put("/api/platforms/{pid}", dependencies=[Depends(require_auth)])
|
||||
@@ -219,6 +222,7 @@ def create_app(cfg: Config | None = None) -> FastAPI:
|
||||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
if cur.rowcount == 0:
|
||||
raise HTTPException(status_code=404, detail="平台不存在")
|
||||
logger.info("更新平台 id=%s 字段: %s", pid, ", ".join(fields))
|
||||
return {"id": pid}
|
||||
|
||||
@app.delete("/api/platforms/{pid}", dependencies=[Depends(require_auth)])
|
||||
@@ -227,6 +231,7 @@ def create_app(cfg: Config | None = None) -> FastAPI:
|
||||
cur = conn.execute("DELETE FROM platforms WHERE id=?", (pid,))
|
||||
if cur.rowcount == 0:
|
||||
raise HTTPException(status_code=404, detail="平台不存在")
|
||||
logger.info("删除平台 id=%s", pid)
|
||||
return {"ok": True}
|
||||
|
||||
# ---------- 账号 ----------
|
||||
@@ -267,6 +272,7 @@ def create_app(cfg: Config | None = None) -> FastAPI:
|
||||
aid = cur.lastrowid
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
logger.info("创建账号: %s (id=%s, 平台id=%s)", body.name, aid, body.platform_id)
|
||||
return {"id": aid}
|
||||
|
||||
@app.put("/api/accounts/{aid}", dependencies=[Depends(require_auth)])
|
||||
@@ -300,6 +306,7 @@ def create_app(cfg: Config | None = None) -> FastAPI:
|
||||
)
|
||||
if cur.rowcount == 0:
|
||||
raise HTTPException(status_code=404, detail="账号不存在")
|
||||
logger.info("更新账号 id=%s 字段: %s", aid, ", ".join(fields))
|
||||
return {"id": aid}
|
||||
|
||||
@app.delete("/api/accounts/{aid}", dependencies=[Depends(require_auth)])
|
||||
@@ -308,6 +315,7 @@ def create_app(cfg: Config | None = None) -> FastAPI:
|
||||
cur = conn.execute("DELETE FROM accounts WHERE id=?", (aid,))
|
||||
if cur.rowcount == 0:
|
||||
raise HTTPException(status_code=404, detail="账号不存在")
|
||||
logger.info("删除账号 id=%s", aid)
|
||||
return {"ok": True}
|
||||
|
||||
@app.post("/api/accounts/{aid}/check", dependencies=[Depends(require_auth)])
|
||||
@@ -392,6 +400,7 @@ def create_app(cfg: Config | None = None) -> FastAPI:
|
||||
changed = True
|
||||
if changed:
|
||||
save_config(cfg)
|
||||
logger.info("设置已更新: %s", ", ".join(f for f in ("global_interval_seconds", "retry_count", "timeout_seconds", "max_workers", "telegram_bot_token", "telegram_chat_id") if getattr(body, f) is not None))
|
||||
return {"ok": True}
|
||||
|
||||
@app.post("/api/settings/password", dependencies=[Depends(require_auth)])
|
||||
@@ -400,6 +409,7 @@ def create_app(cfg: Config | None = None) -> FastAPI:
|
||||
raise HTTPException(status_code=401, detail="旧密码错误")
|
||||
cfg.password = body.new_password
|
||||
save_config(cfg)
|
||||
logger.info("管理密码已修改")
|
||||
return {"ok": True}
|
||||
|
||||
# ---------- 静态前端 ----------
|
||||
|
||||
Reference in New Issue
Block a user