From c4fcc086bea0cb001d2e50628b8bd92f8c7c0b6f Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 23 Aug 2026 08:25:02 -0500 Subject: [PATCH] fix: show anchor names on blacklist; redesign settings with tabs Co-authored-by: Cursor --- backend/app/db.py | 43 +- desktop/src/pages/BlacklistPage.tsx | 14 +- frontend/src/app/blacklist/page.tsx | 20 +- frontend/src/app/settings/page.tsx | 763 ++++++++++++++++------------ 4 files changed, 506 insertions(+), 334 deletions(-) diff --git a/backend/app/db.py b/backend/app/db.py index d31aca1..fdf1873 100644 --- a/backend/app/db.py +++ b/backend/app/db.py @@ -1366,12 +1366,53 @@ def is_blacklisted(room_id: str, url: str = "") -> dict[str, Any] | None: conn.close() +def _blacklist_resolve_anchor(conn: sqlite3.Connection, room_id: str, value: str) -> str: + rid = (room_id or "").strip() + val = (value or "").strip() + if rid: + row = conn.execute( + "SELECT last_anchor, note FROM rooms WHERE room_id = ? ORDER BY updated_at DESC LIMIT 1", + (rid,), + ).fetchone() + if row: + name = str(row["last_anchor"] or row["note"] or "").strip() + if name: + return name + row = conn.execute( + "SELECT anchor_name FROM sessions WHERE room_id = ? ORDER BY started_at DESC LIMIT 1", + (rid,), + ).fetchone() + if row and row["anchor_name"]: + return str(row["anchor_name"]).strip() + if val: + row = conn.execute( + """ + SELECT last_anchor, note FROM rooms + WHERE room_id = ? OR url LIKE ? OR note LIKE ? OR last_anchor LIKE ? + ORDER BY updated_at DESC LIMIT 1 + """, + (val, f"%{val}%", f"%{val}%", f"%{val}%"), + ).fetchone() + if row: + name = str(row["last_anchor"] or row["note"] or "").strip() + if name: + return name + return "" + + def list_blacklist() -> list[dict[str, Any]]: with _lock: conn = _connect() try: rows = conn.execute("SELECT * FROM blacklist ORDER BY created_at DESC").fetchall() - return [dict(r) for r in rows] + items: list[dict[str, Any]] = [] + for row in rows: + item = dict(row) + item["anchor_name"] = _blacklist_resolve_anchor( + conn, str(item.get("room_id") or ""), str(item.get("value") or "") + ) + items.append(item) + return items finally: conn.close() diff --git a/desktop/src/pages/BlacklistPage.tsx b/desktop/src/pages/BlacklistPage.tsx index af5616e..80ff2a1 100644 --- a/desktop/src/pages/BlacklistPage.tsx +++ b/desktop/src/pages/BlacklistPage.tsx @@ -11,6 +11,7 @@ type Item = { id: string; value: string; room_id?: string; + anchor_name?: string; reason?: string; created_at?: number; }; @@ -65,9 +66,10 @@ export default function BlacklistPage() { } async function remove(item: Item) { + const label = item.anchor_name || item.value; const ok = await confirm({ title: "移出黑名单", - message: `确定移除「${item.value}」?相关房间将恢复可监控状态。`, + message: `确定移除「${label}」?相关房间将恢复可监控状态。`, confirmLabel: "移除", destructive: true, }); @@ -132,8 +134,9 @@ export default function BlacklistPage() { - + + @@ -142,8 +145,11 @@ export default function BlacklistPage() { {items.map((item) => ( - - + + +
内容直播间名称 房间号匹配内容 原因 时间 操作
{item.value}{item.room_id || "—"}{item.anchor_name || "—"}{item.room_id || "—"} + {item.value} + {item.reason || "—"} {fmtTs(item.created_at)} diff --git a/frontend/src/app/blacklist/page.tsx b/frontend/src/app/blacklist/page.tsx index 7c6f4a5..6713910 100644 --- a/frontend/src/app/blacklist/page.tsx +++ b/frontend/src/app/blacklist/page.tsx @@ -13,6 +13,7 @@ type Item = { id: string; value: string; room_id?: string; + anchor_name?: string; reason?: string; created_at?: number; }; @@ -67,9 +68,10 @@ export default function BlacklistPage() { } async function remove(item: Item) { + const label = item.anchor_name || item.value; const ok = await confirm({ title: "移出黑名单", - message: `确定移除「${item.value}」?相关房间将恢复可监控状态。`, + message: `确定移除「${label}」?相关房间将恢复可监控状态。`, confirmLabel: "移除", destructive: true, }); @@ -131,11 +133,12 @@ export default function BlacklistPage() { ) : (
- +
- + + @@ -144,10 +147,15 @@ export default function BlacklistPage() { {items.map((item) => ( - - + + + - +
内容直播间名称 房间号匹配内容 原因 时间 操作
{item.value}{item.room_id || "—"} + {item.anchor_name || —} + {item.room_id || "—"} + {item.value} + {item.reason || "—"}{fmtTs(item.created_at)}{fmtTs(item.created_at)} + + + ); +} + export default function SettingsPage() { const toast = useToast(); const [settings, setSettings] = useState({}); @@ -31,6 +98,7 @@ export default function SettingsPage() { const [msg, setMsg] = useState(""); const [error, setError] = useState(""); const [notifPerm, setNotifPerm] = useState("default"); + const [tab, setTab] = useState("runtime"); const load = useCallback(async () => { setLoading(true); @@ -222,95 +290,223 @@ export default function SettingsPage() { return ( -
-

⚙️ 设置中心

-

防风控参数、Cookie/代理、Webhook 通知。

+
+
+

⚙️ 设置

+

按模块分组,改完记得点底部「保存设置」。

+
+
+ {status?.running ? "抖音监控运行中" : "抖音监控已停"} ·{" "} + {ytStatus?.running ? "YouTube 轮询中" : "YouTube 已停"} +
-
- 监控开关: - - - - - 状态:{status?.running ? "循环运行中" : "未运行"} · 上次检查 {fmtTs(Number(status?.last_check_at || 0))} - +
+ {SETTINGS_TABS.map((item) => ( + + ))}
-
-
- YouTube 分组轮询: - - - - {ytStatus?.running ? "循环运行中" : "未运行"} · 直播 {String((ytStatus?.groups as any)?.live ?? "—")} · 启用{" "} - {String((ytStatus?.groups as any)?.enabled ?? "—")} · 上次 {fmtTs(Number(ytStatus?.last_check_at || 0))} - -
-
- {( - [ - ["yt_offline_interval_sec", "离线复查(秒)", 180], - ["yt_live_interval_sec", "在播复查(秒)", 90], - ["yt_batch_size", "每批数量", 8], - ["yt_request_gap_sec", "请求间隔(秒)", 2], - ] as const - ).map(([key, label, fallback]) => ( - - ))} -
-

开播/停播沿用上方「Webhook / 浏览器通知」开关;静默时段内暂停 YouTube 轮询。

-
+
+ {tab === "runtime" ? ( + <> + +
+ void toggleMonitor(true)} + onDisable={() => void toggleMonitor(false)} + /> + + + {status?.running ? "循环运行中" : "未运行"} · 上次 {fmtTs(Number(status?.last_check_at || 0))} + +
+
-
-
- Shorts 旁路(默认关,不影响监控): - - - - 管理频道 / 任务 → - - - {shortsStatus?.running ? "worker 运行中" : "worker 未运行"} ·{" "} - {shortsStatus?.enabled ? "已启用" : "已关闭"} · 今日{" "} - {JSON.stringify((shortsStatus?.stats as any)?.by_status || {})} - -
+ +
+ void toggleYtMonitor(true)} + onDisable={() => void toggleYtMonitor(false)} + /> + + {ytStatus?.running ? "循环运行中" : "未运行"} · 直播 {String((ytStatus?.groups as any)?.live ?? "—")} · 启用{" "} + {String((ytStatus?.groups as any)?.enabled ?? "—")} · 上次 {fmtTs(Number(ytStatus?.last_check_at || 0))} + +
+

轮询间隔等参数在「YouTube」标签页。

+
+ + +
+ void toggleShorts(true)} + onDisable={() => void toggleShorts(false)} + enableLabel="启用" + disableLabel="关闭" + /> + + 管理频道 / 任务 → + + + {shortsStatus?.running ? "worker 运行中" : "worker 未运行"} ·{" "} + {shortsStatus?.enabled ? "已启用" : "已关闭"} + +
+

采样、OAuth、SOCKS 等详细配置在「Shorts」标签页。

+
+ + ) : null} + + {tab === "douyin" ? ( + <> + +
+ {FIELDS.map((f) => ( + + ))} +
+
+ + +
+ + +
+ + + +
+
+
+ + +
+