117 lines
4.6 KiB
TypeScript
117 lines
4.6 KiB
TypeScript
import { request } from '../../lib/http'
|
|
import type { ContinuityDiagnosis, ContinuityInput, ContinuityObservation, ContinuityReview } from './continuity.types'
|
|
|
|
/**
|
|
* 校验选择属于同集正式顺序的相邻两到三镜。
|
|
* @param selected 已选顺序
|
|
* @param ordered 当前集完整顺序
|
|
* @returns 是否可以提交诊断
|
|
*/
|
|
export function continuitySelectionValid(selected: string[], ordered: string[]) {
|
|
const start = ordered.indexOf(selected[0] ?? '')
|
|
return (
|
|
selected.length >= 2 &&
|
|
selected.length <= 3 &&
|
|
start >= 0 &&
|
|
selected.every((id, i) => ordered[start + i] === id) &&
|
|
new Set(selected).size === selected.length
|
|
)
|
|
}
|
|
|
|
/**
|
|
* 提交时校验逐镜观察,无法判断使用真实 unknown/null,不猜测证据。
|
|
* @param observation 人工观察
|
|
* @param shotIds 正式镜头顺序
|
|
* @returns 是否满足正式 Schema
|
|
*/
|
|
export function validObservation(observation: ContinuityObservation | null, shotIds: string[]) {
|
|
return (
|
|
!!observation &&
|
|
/^[a-f0-9]{64}$/.test(observation.expectedFingerprint) &&
|
|
observation.landmarks.every(item => !!item.trim() && item.trim().length <= 120) &&
|
|
observation.landmarks[0].trim() !== observation.landmarks[1].trim() &&
|
|
observation.frames.length === shotIds.length &&
|
|
observation.frames.every(
|
|
(frame, i) =>
|
|
frame.shotId === shotIds[i] &&
|
|
!!frame.evidence.trim() &&
|
|
frame.evidence.trim().length <= 500 &&
|
|
frame.features.length > 0 &&
|
|
frame.features.length <= 24 &&
|
|
new Set(frame.features.map(item => item.key.trim())).size === frame.features.length &&
|
|
frame.features.every(
|
|
item =>
|
|
!!item.key.trim() &&
|
|
item.key.trim().length <= 120 &&
|
|
!!item.evidence.trim() &&
|
|
item.evidence.trim().length <= 500 &&
|
|
(item.side !== undefined) !== (item.count !== undefined) &&
|
|
(item.count === undefined ||
|
|
item.count === null ||
|
|
(Number.isInteger(item.count) && item.count >= 0 && item.count <= 100))
|
|
)
|
|
)
|
|
)
|
|
}
|
|
|
|
/** 公共诊断状态中文,不将证据不足表现为通过。 */
|
|
export const continuityStatusLabels: Record<string, string> = {
|
|
passed: '通过',
|
|
failed: '未通过',
|
|
needs_review: '待人工复核',
|
|
insufficient_evidence: '证据不足',
|
|
stale: '已失效'
|
|
}
|
|
/** 历史失效原因只在展示层转为中文。 */
|
|
export const continuityInvalidationLabels: Record<string, string> = {
|
|
primary_changed: '主首帧已变化',
|
|
evidence_changed: '正式来源、布局或审核证据已变化',
|
|
current_evidence_unavailable: '当前证据不足',
|
|
group_scope_changed: '镜头或场景范围已变化'
|
|
}
|
|
/**
|
|
* 项目连续性接口路径。
|
|
* @param projectId 正式项目
|
|
* @returns 同项目路径
|
|
*/
|
|
function path(projectId: string) {
|
|
return `/projects/${encodeURIComponent(projectId)}/storyboard-keyframes/continuity`
|
|
}
|
|
/** 连续性只读诊断与独立审核记录,不修改 Primary。 */
|
|
export const continuityApi = {
|
|
/**
|
|
* 免费读取诊断或消费人工观察。
|
|
* @param projectId 项目范围
|
|
* @param input 正式镜头和本次指纹
|
|
* @param signal 取消失效查询
|
|
* @returns 诊断结果
|
|
*/
|
|
diagnose: (projectId: string, input: ContinuityInput, signal?: AbortSignal) =>
|
|
request<ContinuityDiagnosis>(`${path(projectId)}/diagnosis`, {
|
|
method: 'POST',
|
|
body: input,
|
|
signal,
|
|
timeoutMs: 0
|
|
}),
|
|
/**
|
|
* 保存本次明确审核,重复参数由服务端幂等复用。
|
|
* @param projectId 项目范围
|
|
* @param input 本次观察指纹和真实审核人
|
|
* @returns 不可变审核记录
|
|
*/
|
|
save: (projectId: string, input: ContinuityInput & { reviewer: string }) =>
|
|
request<ContinuityReview>(`${path(projectId)}/reviews`, { method: 'POST', body: input, timeoutMs: 0 }),
|
|
/**
|
|
* 回读原始结论及当前失效原因。
|
|
* @param projectId 项目范围
|
|
* @param reviewId 正式审核编号
|
|
* @param signal 取消过期读取
|
|
* @returns 历史审核与当前性
|
|
*/
|
|
review: (projectId: string, reviewId: string, signal?: AbortSignal) =>
|
|
request<ContinuityReview>(`${path(projectId)}/reviews/${encodeURIComponent(reviewId)}`, {
|
|
signal,
|
|
timeoutMs: 0
|
|
})
|
|
}
|