fix desktop account status display

This commit is contained in:
2026-05-14 21:43:25 +08:00
parent 75b407ec6b
commit 639516f374
3 changed files with 165 additions and 27 deletions
@@ -18,15 +18,21 @@ export const DONGCHEDI_PLATFORM_EXCEPTION_MESSAGE =
const PUBLISH_PLATFORM_LABELS: Record<string, string> = {
baijiahao: '百家号',
bilibili: 'bilibili',
deepseek: 'DeepSeek',
dongchedi: '懂车帝',
doubao: '豆包',
jianshu: '简书',
juejin: '稀土掘金',
kimi: 'Kimi',
qiehao: '企鹅号',
qwen: '通义千问',
smzdm: '什么值得买',
sohuhao: '搜狐号',
toutiaohao: '头条号',
wangyihao: '网易号',
weixin_gzh: '微信公众号',
wenxin: '文心一言',
yuanbao: '混元 / 元宝',
zhihu: '知乎',
zol: '中关村在线',
}
@@ -36,6 +42,96 @@ function normalizeErrorText(value: string | null | undefined): string | null {
return trimmed ? trimmed : null
}
export function translatePublisherPlatform(platform: string | null | undefined): string {
const normalized = platform?.trim()
if (!normalized) {
return '当前平台'
}
return PUBLISH_PLATFORM_LABELS[normalized.toLowerCase()] ?? normalized
}
function errorPlatformSuffix(message: string, code: string): string | null {
const prefix = `${code}:`
return message.toLowerCase().startsWith(prefix)
? message.slice(prefix.length).trim() || null
: null
}
export function normalizeDesktopAccountErrorMessage(
message: string | null | undefined,
platform?: string | null,
): string | null {
const normalized = normalizeErrorText(message)
if (!normalized) {
return null
}
const sessionExpiredPlatform = errorPlatformSuffix(
normalized,
'desktop_account_session_expired',
)
if (sessionExpiredPlatform !== null) {
const platformLabel = translatePublisherPlatform(sessionExpiredPlatform || platform)
return `${platformLabel}登录态已失效,请重新授权后再试。`
}
const unsupportedPlatform = errorPlatformSuffix(normalized, 'desktop_platform_not_supported')
if (unsupportedPlatform !== null) {
const platformLabel = translatePublisherPlatform(unsupportedPlatform || platform)
return `${platformLabel}暂时还不支持这个操作。`
}
const platformLabel = translatePublisherPlatform(platform)
switch (normalized) {
case 'desktop_account_bind_window_closed':
return '授权窗口已关闭,本次绑定没有完成。重新点击“绑定账号”即可继续。'
case 'desktop_account_bind_limit_reached':
return '当前最多同时打开 2 个授权窗口。请先完成或关闭已有授权窗口,再继续新的绑定。'
case 'desktop_account_upsert_failed':
return '平台侧授权已经完成,但客户端回写账号信息失败。请稍后重试。'
case 'desktop_account_bind_failed':
return '授权流程执行失败,请稍后重新发起绑定。'
case 'desktop_account_sync_conflict':
return '当前账号状态刚刚发生了变化。请先刷新列表,再重试这次操作。'
case 'desktop_account_delete_failed':
return '服务端解绑没有成功完成,请稍后重试。'
case 'desktop_account_auth_expired':
return platform
? `${platformLabel}登录态已失效,请重新授权后再试。`
: '发布账号登录态已失效,请重新授权后再试。'
case 'desktop_account_risk_control':
return platform
? `${platformLabel}账号疑似触发风控,请打开平台处理验证或等待限制解除后再重试。`
: '发布账号疑似触发风控,请打开平台处理验证或等待限制解除后再重试。'
case 'desktop_account_challenge_required':
return platform
? `${platformLabel}账号需要完成人机验证,请打开平台完成验证后再重试。`
: '发布账号需要完成人机验证,请打开平台完成验证后再重试。'
case 'desktop_account_probe_pending':
return platform
? `${platformLabel}账号最近校验失败,已暂缓执行任务。请刷新状态后再重试。`
: '发布账号最近校验失败,已暂缓执行任务。请刷新状态后再重试。'
case 'desktop_account_client_missing':
return '所选账号还没有绑定桌面客户端,暂时无法发布。'
case 'desktop_account_not_found':
return '所选桌面账号不存在,请刷新后重试。'
case 'desktop_account_not_publishable':
return '所选账号需要重新授权后才能发布。'
case 'desktop_account_lookup_failed':
return '查询桌面账号失败,请刷新后重试。'
case 'desktop_accounts_query_failed':
return '查询桌面账号列表失败,请刷新后重试。'
case 'desktop_account_sync_version_required_existing':
return '账号同步版本已失效,请刷新后重试。'
case 'desktop_account_patch_failed':
return '更新桌面账号失败,请稍后重试。'
case 'desktop_account_request_delete_failed':
return '更新账号解绑状态失败,请稍后重试。'
default:
return null
}
}
function isDongchediPlatform(platform?: string | null): boolean {
return platform?.trim().toLowerCase() === 'dongchedi'
}
@@ -172,6 +268,10 @@ export function normalizePublisherErrorMessage(
message: string | null | undefined,
platform?: string | null,
): string | null {
const desktopAccountMessage = normalizeDesktopAccountErrorMessage(message, platform)
if (desktopAccountMessage) {
return desktopAccountMessage
}
if (message === 'compliance_blocked') {
return '内容合规检测已阻断本次发布,请修改文章后重新发布。'
}