Files
creator-hub/web/src/utils/account-collection-status.ts
T
rogee e50bed9ad8
douyin-release-gate / verify (push) Failing after 18m54s
feat: add account events and private message management
Add Douyin notification polling, event details, and manual multi-account private messaging.

Refine environment memory settings, account operations, login collection recovery, and message UI; update tests and documentation.
2026-10-07 10:23:05 +08:00

42 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export type CollectionCheckpoint = {
status?: string;
last_completed_at?: string | null;
last_error?: string | null;
};
const labels: Record<string, { text: string; color: string }> = {
idle: { text: '待采集', color: 'default' },
pending: { text: '待采集', color: 'default' },
succeeded: { text: '采集完成', color: 'success' },
running: { text: '采集运行中', color: 'processing' },
failed: { text: '采集失败', color: 'error' },
blocked: { text: '采集受阻', color: 'warning' },
};
export function collectionStatusPresentation(checkpoint?: CollectionCheckpoint | null) {
const reason = checkpoint?.last_error || '';
if (reason.includes('browser is awaiting user login')) {
return {
text: '需要登录',
color: 'warning',
reason: '浏览器需要登录,请登录并同步账号后重试。',
};
}
const state = checkpoint?.status ? labels[checkpoint.status] : undefined;
return { ...(state || { text: '状态未知', color: 'default' }), reason };
}
const accountStatusPriority = ['需要登录', '采集失败', '采集受阻', '状态未知', '采集运行中', '待采集', '采集完成'];
export function accountCollectionStatusPresentation(
works?: CollectionCheckpoint | null,
comments?: CollectionCheckpoint | null,
) {
const states = [works, comments].map(collectionStatusPresentation);
const primary = states.reduce((current, candidate) =>
accountStatusPriority.indexOf(current.text) <= accountStatusPriority.indexOf(candidate.text) ? current : candidate,
);
const reasons = [...new Set(states.map(state => state.reason).filter(Boolean))];
return { ...primary, reason: reasons.join(';') };
}