feat(monitor): 组头上加一个跳到博主主页的按钮
Deploy VitePress site to Pages / build (push) Canceled after 0s
Deploy VitePress site to Pages / Deploy (push) Canceled after 0s

`creator_hash` 是单向的,拼不出主页地址 —— 所以这个 id 必须在采集时单独存下来。
抖音的资料接口本来就返回 sec_uid,只是之前没落库。

* `monitor_creator_stat` 加 `creator_id` 列(老数据默认空,下一次采集补上);
* 链接在 `adapters.creator_url()` 里拼,**空串是有意义的返回值**:平台不认识、
  或者没拿到 id,就返回空,界面据此不画按钮 —— 画一个点开 404 的按钮比不画糟;
* 没有作品的博主照样有链接:他恰恰是你想点进去看的那个人。

已知缺口:小红书那条路(爬虫子进程)根本不落创作者资料,所以那边没有链接。
This commit is contained in:
2026-10-11 08:52:51 +08:00
parent 65fc16ddc9
commit 44277600e4
10 changed files with 172 additions and 0 deletions
+34
View File
@@ -852,6 +852,7 @@ def _profile(creator_hash: str = "hash", **extra) -> Dict[str, Any]:
record: Dict[str, Any] = {
"creator_hash": creator_hash,
"nickname": "博主",
"creator_id": "MS4wLjABAAAAtestsuid",
"unique_id": "abc",
"fans": 12000,
"total_favorited": 83000,
@@ -976,3 +977,36 @@ class TestCreatorStatSnapshots:
)
assert [s.fans for s in stats] == [12000, 12300]
class TestCreatorIdIsStored:
"""主页 id 要单独存下来 —— ``creator_hash`` 是单向的,拼不出主页地址。"""
@pytest.mark.asyncio
async def test_the_profile_id_lands_on_the_snapshot(self, db, tmp_path):
task = await _make_task(db, platform="dy")
run = await _make_run(db, task, started_at=1)
_write_run_dir(
tmp_path, [_dy_note("1")], comments=[], subdir="douyin", profiles=[_profile()]
)
await ingest_run(db, run, task, tmp_path)
stat = await db.scalar(select(MonitorCreatorStat))
assert stat.creator_id == "MS4wLjABAAAAtestsuid"
@pytest.mark.asyncio
async def test_a_missing_id_is_empty_not_a_crash(self, db, tmp_path):
"""老数据/别的平台没有这个字段 —— 空串,界面据此不画按钮。"""
task = await _make_task(db, platform="dy")
run = await _make_run(db, task, started_at=1)
_write_run_dir(
tmp_path,
[_dy_note("1")],
comments=[],
subdir="douyin",
profiles=[_profile(creator_id="")],
)
await ingest_run(db, run, task, tmp_path)
assert (await db.scalar(select(MonitorCreatorStat))).creator_id == ""