From 1dca78b6db914bd8319de136fbc5c4b5bdd88efb Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Sat, 24 Oct 2026 16:45:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(webui):=20=E8=B6=85=E7=BA=A7=E7=BC=96?= =?UTF-8?q?=E5=AF=BC=200=20=E6=9D=A1=E4=BD=9C=E5=93=81=E6=97=B6=E8=AF=B4?= =?UTF-8?q?=E6=B8=85=E6=98=AF=E5=93=AA=E5=87=A0=E4=B8=AA=E6=B4=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实测踩到:按 10-22~10-24 查返回「活动 4 个、作品 0 条」,看着像链接没取到。 那 4 个活动全是排期在未来的(10.26/10.27/10.28/10.29),还没人发布。活动名 里的日期只是名字,不是创建时间 —— 这句也写进空态里。 --- api/monitor/superdir.py | 13 ++++++ tests/test_monitor_superdir.py | 43 +++++++++++++++++++ webui/src/components/monitor/SuperDirTool.tsx | 25 +++++++++-- webui/src/types/monitor.ts | 12 ++++++ 4 files changed, 90 insertions(+), 3 deletions(-) diff --git a/api/monitor/superdir.py b/api/monitor/superdir.py index 1e02db8..3af3010 100644 --- a/api/monitor/superdir.py +++ b/api/monitor/superdir.py @@ -402,6 +402,19 @@ async def preview( "start": start_day.isoformat(), "end": end_day.isoformat(), "activities": len(activities), + # 匹配到的活动原样带回去。**0 条作品时它就是唯一能解释为什么的东西**: + # 活动建了但还没人发布(尤其是排期在未来的活动),界面不能只显示一个「0」。 + # 注意活动名里的日期("10.23")是活动名,不是创建时间 —— 这两者经常被当成一回事。 + "matched_activities": [ + { + "id": _as_int(activity.get("id")), + "title": str(activity.get("title") or ""), + "created_at": _as_int(activity.get("created_at")), + "total_count": _as_int(activity.get("total_count")), + "published_count": _as_int(activity.get("published_count")), + } + for activity in activities + ], "videos": total, "creators": len({row["nickname"] for row in rows if row["nickname"]}), "skipped": skipped, diff --git a/tests/test_monitor_superdir.py b/tests/test_monitor_superdir.py index b458de1..949b6a7 100644 --- a/tests/test_monitor_superdir.py +++ b/tests/test_monitor_superdir.py @@ -86,6 +86,49 @@ class TestPreview: assert result["videos"] == 1 assert result["rows"][0]["aweme_id"] == AWEME_A + @pytest.mark.asyncio + async def test_matched_activities_explain_a_zero_video_result(self, monkeypatch): + """活动建了但还没人发布 —— 0 条作品是真的,界面上得说得出是哪几个活动。 + + 实测踩到过:运营按「10-22 ~ 10-24」查,返回 4 个活动、0 条作品,以为链接没取到。 + 那 4 个活动全是排期在未来的(10.26/10.27/10.28/10.29),当然还没有作品。 + """ + + async def fake_activities(token, client): + return [ + { + "id": 9, + "title": "10.26 漫展", + "created_at": superdir._day_start(date(2026, 10, 22)) + 3600, + "total_count": 0, + "published_count": 0, + } + ] + + async def fake_videos(token, activity_id, client): + return [] + + async def fake_token(session, platform=superdir.adapters.PLATFORM_DY): + return "token" + + monkeypatch.setattr(superdir, "_fetch_activities", fake_activities) + monkeypatch.setattr(superdir, "_fetch_videos", fake_videos) + monkeypatch.setattr(superdir, "get_token", fake_token) + + result = await superdir.preview(None, "2026-10-22", "2026-10-24") + + assert result["videos"] == 0 + assert result["rows"] == [] + assert result["matched_activities"] == [ + { + "id": 9, + "title": "10.26 漫展", + "created_at": superdir._day_start(date(2026, 10, 22)) + 3600, + "total_count": 0, + "published_count": 0, + } + ] + @pytest.mark.asyncio async def test_unpublished_and_private_videos_are_skipped(self, monkeypatch): async def fake_activities(token, client): diff --git a/webui/src/components/monitor/SuperDirTool.tsx b/webui/src/components/monitor/SuperDirTool.tsx index cd5e4e5..4c7fc56 100644 --- a/webui/src/components/monitor/SuperDirTool.tsx +++ b/webui/src/components/monitor/SuperDirTool.tsx @@ -208,9 +208,28 @@ export function SuperDirTool({ open, onOpenChange }: SuperDirToolProps) { ))} ) : ( -

- 这段时间里没有可导入的作品 -

+
+

+ 这段时间创建了 {data.matched_activities.length} 个分发活动,但还没有已发布的作品: +

+ {data.matched_activities.map((activity) => ( +
+ + {activity.title || `活动 ${activity.id}`} + + + 创建 {formatTs(activity.created_at)} · 已发布{' '} + {activity.published_count}/{activity.total_count} + +
+ ))} +

+ 活动名里的日期只是活动名,不是创建时间;排期在未来的活动通常还没有作品。 +

+
)} )} diff --git a/webui/src/types/monitor.ts b/webui/src/types/monitor.ts index 67f5189..99f9703 100644 --- a/webui/src/types/monitor.ts +++ b/webui/src/types/monitor.ts @@ -599,11 +599,23 @@ export interface SuperDirFailedActivity { error: string } +/** 匹配到的分发活动。0 条作品时用它解释「为什么是 0」。 */ +export interface SuperDirMatchedActivity { + id: number + title: string + created_at: number + /** 活动里计划/分配的作品数。 */ + total_count: number + /** 已经发布出来的作品数。 */ + published_count: number +} + export interface SuperDirPreviewResponse { start: string end: string /** 区间内创建的分发活动数。 */ activities: number + matched_activities: SuperDirMatchedActivity[] /** 能用的作品条数(去重、去掉私密和没发布之后)。 */ videos: number creators: number