feat: add MCP creator screenshot metrics recognition
This commit is contained in:
@@ -21,6 +21,33 @@ type ScheduledTask = {
|
||||
|
||||
type CollectionSource = "automatic" | "catchup" | "manual";
|
||||
|
||||
function userFacingCollectionError(error: unknown) {
|
||||
const message = error instanceof Error ? error.message : String(error ?? "");
|
||||
const normalized = message.toLowerCase();
|
||||
if (
|
||||
/cookie|登录|登陆|授权|access.?token|未登录|未授权|401|403/.test(
|
||||
normalized,
|
||||
)
|
||||
) {
|
||||
return "采集 Cookie 已过期或无权限";
|
||||
}
|
||||
if (
|
||||
/链接|link|url|404|not found|不存在|删除|失效|无法识别.*笔记/.test(
|
||||
normalized,
|
||||
)
|
||||
) {
|
||||
return "笔记链接失效或不可访问";
|
||||
}
|
||||
if (
|
||||
/超时|timeout|fetch failed|network|502|503|暂时不可用|响应空/.test(
|
||||
normalized,
|
||||
)
|
||||
) {
|
||||
return "采集服务暂时不可用";
|
||||
}
|
||||
return "笔记链接失效或采集 Cookie 过期";
|
||||
}
|
||||
|
||||
function utcDay(value: string) {
|
||||
const match = value.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
||||
if (!match) return null;
|
||||
@@ -311,8 +338,9 @@ export async function collectDistributionMetrics(
|
||||
]);
|
||||
return { skipped: false, likes, comments, collects, shares };
|
||||
} catch (error) {
|
||||
const message =
|
||||
error instanceof Error ? error.message : "公开数据采集失败";
|
||||
const detail = error instanceof Error ? error.message : String(error);
|
||||
const message = userFacingCollectionError(error);
|
||||
console.error("[KOC LOOP] collection failed", { detail, distributionId });
|
||||
await db.batch([
|
||||
db
|
||||
.prepare(
|
||||
|
||||
Reference in New Issue
Block a user