import { storyboardApi } from '../storyboard/api' import { request } from '../../lib/http' import type { DiagnosisLocation } from '../breakdown/diagnosis' import type { StoryboardHandRepairHistory } from '../breakdown/types' import type { StoryboardRecheck, ReviewBaselinePreview, StoryboardApproval, StoryboardApprovalState, StoryboardReviewInput, ProductionEntryReadiness, LocatedStoryboardShot, FormalShotRepairPreview, FormalRepairCandidate, FormalRepairInput, FormalRepairResult, BeatSubjectPreview, BeatSubjectRepairResult, SubjectRepairInput } from './types' /** * 所有制作前检查都绑定正式项目。 * @param id 正式项目编号 * @returns 编码后的项目路径 */ function root(id: string): string { return `/projects/${encodeURIComponent(id)}` } /** 正式分镜审核、版本化修复和制作入口,不使用测试路由。 */ export const preparationApi = { /** * 只读复检,不自动审核。 * @param id 当前项目编号 * @param signal 取消旧查询 * @returns 正式接口的实际业务回执 */ recheck: (id: string, signal?: AbortSignal) => request(`${root(id)}/breakdown/storyboard-quality-recheck`, { signal }), /** * 读取旧分镜规则来源的确认条件。 * @param id 当前项目编号 * @param signal 取消旧查询 * @returns 正式接口的实际业务回执 */ baseline: (id: string, signal?: AbortSignal) => request(`${root(id)}/breakdown/storyboard-review-baseline/preview`, { signal }), /** * 明确确认历史规则来源,不改写历史拆解。 * @param id 当前项目编号 * @param input 人工核对内容与原始版本 * @returns 正式接口的实际业务回执 */ confirmBaseline: (id: string, input: StoryboardReviewInput) => request(`${root(id)}/breakdown/storyboard-review-baseline/confirm`, { method: 'POST', body: input }), /** * 读取人工审核凭据及当前内容证据。 * @param id 当前项目编号 * @param signal 取消旧查询 * @returns 正式接口的实际业务回执 */ approval: (id: string, signal?: AbortSignal) => request(`${root(id)}/storyboard/quality-confirmation`, { signal }), /** * 明确确认当前分镜的整体审核。 * @param id 当前项目编号 * @param input 人工审核内容与原始版本 * @returns 正式接口的实际业务回执 */ confirmApproval: (id: string, input: StoryboardReviewInput) => request(`${root(id)}/storyboard/quality-confirmation`, { method: 'POST', body: input }), /** * 只读制作入口结论,必须在制作计划前核对。 * @param id 当前项目编号 * @param signal 取消旧查询 * @returns 正式接口的实际业务回执 */ entry: (id: string, signal?: AbortSignal) => request(`${root(id)}/production/entry-readiness`, { signal }), /** * 通过精确坐标获得正式镜头和内容版本。 * @param id 当前项目编号 * @param target 精确的剧集段落及镜头 * @param signal 取消旧查询 * @returns 正式接口的实际业务回执 */ locate: (id: string, target: Required, signal?: AbortSignal) => request(`${root(id)}/breakdown/storyboard-shots/locate?${new URLSearchParams({ episodeNo: String(target.episodeNo), beatNo: String(target.beatNo), shotNo: String(target.shotNo) })}`, { signal }), /** * 读取当前正式镜头可编辑动作和确定性建议。 * @param id 当前项目编号 * @param shotId 正式镜头编号 * @param signal 取消旧查询 * @returns 正式接口的实际业务回执 */ repairPreview: (id: string, shotId: string, signal?: AbortSignal) => request(`${root(id)}/breakdown/storyboard-shot-repair/preview/${encodeURIComponent(shotId)}`, { signal }), /** * 用户确认费用后才调用文字模型生成建议,不保存镜头。 * @param id 当前项目编号 * @param shotId 正式镜头编号 * @param expectedFingerprint 已核对的原始镜头内容 * @returns 正式接口的实际业务回执 */ repairCandidate: (id: string, shotId: string, expectedFingerprint: string) => request(`${root(id)}/breakdown/storyboard-shot-repair/candidate`, { method: 'POST', body: { shotId, expectedFingerprint }, timeoutMs: 0 }), /** * 明确保存动作,事务内继续检查来源、资产和任务。 * @param id 当前项目编号 * @param input 明确确认的动作修订与原始版本 * @returns 正式接口的实际业务回执 */ repair: (id: string, input: FormalRepairInput) => request(`${root(id)}/breakdown/storyboard-shot-repair`, { method: 'POST', body: input }), /** * 按需读取不可变正式修订历史。 * @param id 当前项目编号 * @param shotId 正式镜头编号 * @param signal 取消旧查询 * @returns 正式接口的实际业务回执 */ revisions: (id: string, shotId: string, signal?: AbortSignal) => request(`${root(id)}/breakdown/storyboard-shot-revision-history/${encodeURIComponent(shotId)}`, { signal }), /** * 只读核对缺失主体的上游段落和当前镜头证据。 * @param id 当前项目编号 * @param shotId 正式镜头编号 * @param subjectRef 当前项目已有主体 * @param signal 取消旧查询 * @returns 正式接口的实际业务回执 */ beatSubjectPreview: (id: string, shotId: string, subjectRef: string, signal?: AbortSignal) => request(`${root(id)}/breakdown/storyboard-beat-subject-repair/preview`, { method: 'POST', body: { shotId, subjectRef }, signal }), /** * 用户确认后按段落内容版本追加主体。 * @param id 当前项目编号 * @param input 明确确认的段落主体修订与段落版本 * @returns 正式接口的实际业务回执 */ repairBeatSubject: (id: string, input: SubjectRepairInput) => request(`${root(id)}/breakdown/storyboard-beat-subject-repair`, { method: 'POST', body: input }), /** * 只读核对当前镜头主体追加,前置段落证据须已完整。 * @param id 当前项目编号 * @param input 待检查的镜头主体与原始版本 * @param signal 取消旧查询 * @returns 正式接口的实际业务回执 */ subjectPreview: (id: string, input: SubjectRepairInput, signal?: AbortSignal) => request(`${root(id)}/breakdown/storyboard-shot-subject-repair/preview`, { method: 'POST', body: { shotId: input.shotId, subjectRef: input.subjectRef, expectedFingerprint: input.expectedFingerprint, confirmed: true }, signal }), /** * 用户确认后按镜头内容版本追加已有主体。 * @param id 当前项目编号 * @param input 明确确认的镜头主体修订与镜头版本 * @returns 正式接口的实际业务回执 */ repairSubject: (id: string, input: SubjectRepairInput) => request(`${root(id)}/breakdown/storyboard-shot-subject-repair`, { method: 'POST', body: input }) } /** * 覆盖率完整也可能是旧设计,进入制作计划前逐集核对服务明确返回的过期数量。 * @param projectId 当前项目 * @param episodeNos 正式剧集范围 * @param expectedShotCount 入口统计的正式镜头数 * @returns 当前版本检查完成,缺失或过期时抛出可操作错误 */ export async function assertCurrentStoryboardDesigns(projectId: string, episodeNos: number[], expectedShotCount: number): Promise { const numbers = [...new Set(episodeNos)] if (!numbers.length || !Number.isSafeInteger(expectedShotCount) || expectedShotCount <= 0) throw new Error('正式镜头范围尚未确认,请刷新制作前检查。') const records = await Promise.all(numbers.map(async episodeNo => { const [direction, visual] = await Promise.all([storyboardApi.directions(projectId, episodeNo), storyboardApi.visualStates(projectId, episodeNo)]) if (direction.projectId !== projectId || visual.projectId !== projectId || direction.episodeNo !== episodeNo || visual.episodeNo !== episodeNo) throw new Error('设计检查结果与当前项目或剧集不一致。') if (direction.staleCount !== 0 || visual.staleCount !== 0 || direction.shotCount !== direction.directionCount || visual.shotCount !== visual.visualStateCount || direction.coverage !== 1 || visual.coverage !== 1 || direction.shotCount !== visual.shotCount) throw new Error('镜头设计或画面状态已过期、缺失或版本尚未确认,请先补齐或更新设计。') return direction.shotCount })) if (records.reduce((total, count) => total + count, 0) !== expectedShotCount) throw new Error('设计与正式镜头范围不一致,请刷新后核对。') }