v1.4.3: 大模型token/次数统计 + 调用优先级自动切换(全败才报错) + 通知日志查看正文/增强分页/批量删除

This commit is contained in:
2026-08-31 12:55:09 +08:00
parent 3f6abe7ad6
commit 4bbb6150cc
7 changed files with 477 additions and 67 deletions
+48 -1
View File
@@ -114,6 +114,35 @@ def api_logs():
"total": total, "pages": max(1, (total + page_size - 1) // page_size)})
@app.route("/api/logs/delete", methods=["POST"])
def api_logs_delete():
"""批量删除通知日志。POST {ids: [1,2,3]} 或 {all: true}(删除筛选条件下的全部)"""
data = request.get_json(force=True) or {}
ids = [int(x) for x in (data.get("ids") or []) if str(x).isdigit()]
if data.get("all"):
# 删除当前筛选条件下的全部
f_type = data.get("type", "") or None
f_status = data.get("status", "") or None
q = data.get("q", "") or None
ids = db.list_log_ids(type_=f_type, status=f_status, q=q)
n = db.delete_logs(ids)
return jsonify({"ok": True, "deleted": n})
@app.route("/api/logs/<int:lid>")
def api_log_one(lid):
"""取单条通知日志(含 body 正文)"""
row = db.get_log(lid)
if not row:
return jsonify({"ok": False, "error": "not found"})
d = dict(row)
try:
d["article_ids"] = json.loads(d["article_ids"] or "[]")
except Exception:
d["article_ids"] = []
return jsonify({"ok": True, "log": d})
@app.route("/api/errors")
def api_errors():
"""系统错误日志(最近 N 条)"""
@@ -121,6 +150,19 @@ def api_errors():
return jsonify({"ok": True, "errors": db.list_system_errors(limit=limit)})
@app.route("/api/articles/batch")
def api_articles_batch():
"""按 ID 批量取资讯(id+title+url),用于旧日志无 body 时展示链接。"""
ids = [int(x) for x in request.args.get("ids", "").split(",") if x.strip().isdigit()]
if not ids:
return jsonify({"ok": True, "articles": []})
conn = db.get_conn()
marks = ",".join("?" * len(ids))
rows = conn.execute(f"SELECT id, title, url FROM articles WHERE id IN ({marks})", ids).fetchall()
conn.close()
return jsonify({"ok": True, "articles": [dict(r) for r in rows]})
@app.route("/settings")
def settings_page():
auto = db.get_all_settings()
@@ -141,7 +183,8 @@ def settings_page():
merged = dict(dft)
merged.update(v)
auto[k] = merged
return render_template("settings.html", auto=auto, providers=db.list_providers())
return render_template("settings.html", auto=auto, providers=db.list_providers(),
llm_stats=db.llm_stats_summary(), llm_daily=db.llm_stats_daily(14))
# ---------------- API ----------------
@@ -354,6 +397,10 @@ def api_llm():
db.set_active_provider(data["id"])
p = db.get_provider(data["id"])
return jsonify({"ok": True, "name": p["name"] if p else ""})
if action == "move":
# 优先级上移/下移:direction=-1 上移(优先),+1 下移
ok = db.reorder_provider(data["id"], int(data.get("direction", 0)))
return jsonify({"ok": ok, "error": "无法移动(已在边界或不存在)"} if not ok else {"ok": True})
if action == "toggle":
p = db.get_provider(data["id"])
if not p: