48 lines
2.4 KiB
TypeScript
48 lines
2.4 KiB
TypeScript
import { issueLabel } from './model'
|
||
import type { ProductionIssue } from './types'
|
||
|
||
/**
|
||
* 把后端生产原因转换为普通用户可读的中文提示。
|
||
* @param message 后端原始说明或错误信息
|
||
* @returns 页面展示的中文说明
|
||
*/
|
||
export function productionMessage(message: string): string {
|
||
const text = message.trim()
|
||
if (!text) return ''
|
||
if (
|
||
/(?:Primary Keyframe|主首帧|首帧)/i.test(text) &&
|
||
/(?:视觉|画面)(?:质量)?(?:校验|检查).*?(?:未通过|失败)/.test(text)
|
||
)
|
||
return '首帧画面检查未通过,请重新生成或修复首帧。'
|
||
if (/(?:Video Prompt|视频提示词).*未绑定.*(?:Primary Keyframe|首帧)/i.test(text))
|
||
return '视频提示词与当前首帧不一致,请重新生成视频提示词。'
|
||
if (/空间目标绑定.*(?:变化|变更|调整)/.test(text)) return '镜头画面设置已调整,请重新生成并检查首帧。'
|
||
if (/缺少.*(?:Primary Keyframe|主首帧)/i.test(text)) return '还没有可用首帧,请先生成并确认首帧。'
|
||
if (/(?:Primary Keyframe|主首帧).*(?:过期|旧版|参考资产.*变化)/i.test(text))
|
||
return '当前首帧需要更新,请重新生成并检查首帧。'
|
||
if (/fetch failed|failed to fetch|network error/i.test(text)) return '暂时无法连接服务,请稍后重新获取。'
|
||
const translated = text
|
||
.replace(/Storyboard Shot/gi, '镜头')
|
||
.replace(/Primary Keyframe/gi, '首帧')
|
||
.replace(/Video Prompt/gi, '视频提示词')
|
||
.replace(/Motion Plan/gi, '动作设计')
|
||
.replace(/Identity Anchor/gi, '身份母版')
|
||
.replace(/SubjectForm/gi, '主体形态')
|
||
.replace(/Provider/gi, '生成模型')
|
||
.replace(/\bShot\b/gi, '镜头')
|
||
.replace(/服务器内部错误[::]?\s*/g, '')
|
||
.replace(/\s*[::]?\s*\bc[a-z0-9]{20,}\b/g, '')
|
||
.trim()
|
||
return /[\u4e00-\u9fff]/.test(translated) ? translated : '暂时无法读取生成信息,请稍后重新获取。'
|
||
}
|
||
|
||
/**
|
||
* 将就绪检查问题转换为页面说明,不改变原始问题数据。
|
||
* @param issue 后端结构化就绪问题
|
||
* @returns 页面展示的原因与处理建议
|
||
*/
|
||
export function productionIssueText(issue: ProductionIssue): string {
|
||
if (issue.code === 'failed_keyframe_quality') return '首帧画面检查未通过,请重新生成或修复首帧。'
|
||
return productionMessage(issue.reason) || issueLabel(issue.code)
|
||
}
|