86 lines
3.8 KiB
TypeScript
86 lines
3.8 KiB
TypeScript
import type { BreakdownState } from './types'
|
|
import type { CandidateCommitPreview, CandidateCommitCheckPreview } from './candidate.types'
|
|
|
|
/** 安全检查项与用户可理解的阻断原因共用一份映射。 */
|
|
export const candidateCheckLabels: Record<keyof CandidateCommitCheckPreview['checks'], string> = {
|
|
durationBudgetCurrent: '候选预算与当前正式时长一致',
|
|
qualityPolicyMatches: '质量规则与当前已确认版本一致',
|
|
episodeNumbersMatch: '剧集范围与候选一致',
|
|
episodeFingerprintsMatch: '剧本正文版本未变化',
|
|
noActiveExecutions: '没有正在执行的制作任务',
|
|
noActiveVideos: '没有正在生成的视频',
|
|
noSubjectIdentities: '没有需要保护的主体身份',
|
|
noSubjectImages: '没有需要保护的主体图片',
|
|
noProtectedShots: '没有需要保护的镜头资产',
|
|
relationEvidenceValid: '场景、道具关系的来源证据有效'
|
|
}
|
|
/** 必须逐项校验的固定安全门禁,不根据响应动态减少检查项。 */
|
|
export const candidateCheckKeys = [
|
|
'qualityPolicyMatches',
|
|
'durationBudgetCurrent',
|
|
'episodeNumbersMatch',
|
|
'episodeFingerprintsMatch',
|
|
'noActiveExecutions',
|
|
'noActiveVideos',
|
|
'noSubjectIdentities',
|
|
'noSubjectImages',
|
|
'noProtectedShots',
|
|
'relationEvidenceValid'
|
|
] as const
|
|
|
|
/**
|
|
* 安全预检查必须逐项通过且属于当前项目和候选,不能只相信 ready。
|
|
* @param preview 安全预检查回执
|
|
* @param projectId 当前项目
|
|
* @param checkpointId 当前候选版本
|
|
* @returns 是否可进入最终确认
|
|
*/
|
|
export function candidatePreviewReady(
|
|
preview: CandidateCommitPreview | null,
|
|
projectId: string,
|
|
checkpointId?: string
|
|
): boolean {
|
|
if (
|
|
!preview ||
|
|
preview.status === 'already_committed' ||
|
|
preview.projectId !== projectId ||
|
|
preview.checkpointId !== checkpointId ||
|
|
!!preview.durationSourceIssue
|
|
)
|
|
return false
|
|
// 外部 JSON 的布尔值必须严格为 true,不接受缺失值或字符串等真值。
|
|
const flags: unknown[] = [preview.readOnly, preview.ready, ...candidateCheckKeys.map(key => preview.checks?.[key])]
|
|
return flags.every(value => value === true)
|
|
}
|
|
|
|
/**
|
|
* 仅用最新原始快照提示提交条件,实际替换权限仍由后端事务判断。
|
|
* @param state 最新原始拆解快照,禁止传入历史回退拼接结果
|
|
* @returns 完整性阻断原因,空字符串只表示可继续安全预检查,不是提交许可
|
|
*/
|
|
export function candidateCommitIssue(state: BreakdownState | null | undefined): string {
|
|
if (state?.candidateOnly !== true) return '当前最新结果不是候选模式。'
|
|
if (state.storyboardPersisted === true || state.candidateCommitted === true) return '这份候选已经提交。'
|
|
if (state.workflowExecution?.status === 'running') return '候选拆解仍在执行。'
|
|
if (state.storyboardShotValidation?.valid !== true) return '候选分镜尚未通过校验。'
|
|
if (state.storyboardPendingQualityEpisodeNos?.length) return '仍有剧集未通过质量审核,请先修订。'
|
|
if (!state.expectedEpisodeFingerprints || !state.runConfig?.sourceEpisodes?.length)
|
|
return '候选缺少剧本版本信息,请重新生成候选。'
|
|
const episodes = state.storyboardEpisodeShots ?? []
|
|
const source = state.runConfig.sourceEpisodes
|
|
if (
|
|
!state.subjectCandidates?.length ||
|
|
!Array.isArray(state.subjectForms) ||
|
|
episodes.length !== source.length ||
|
|
source.some(
|
|
item =>
|
|
!state.expectedEpisodeFingerprints?.[item.episodeNo] ||
|
|
!episodes.some(
|
|
episode => episode.episodeNo === item.episodeNo && episode.beatShots.some(beat => beat.shots.length)
|
|
)
|
|
)
|
|
)
|
|
return '候选主体或分镜不完整,请先完成拆解。'
|
|
return ''
|
|
}
|