64 lines
2.5 KiB
TypeScript
64 lines
2.5 KiB
TypeScript
import type { ProductionIssue } from './types'
|
||
import type { ShotReferences } from '../storyboard/types'
|
||
|
||
/** 素材定位使用正式 Form ID;无当前关联时只保留主体引用,不猜测形态。 */
|
||
export interface ReferenceTarget {
|
||
subjectRef: string
|
||
subjectId?: string
|
||
formId?: string
|
||
label: string
|
||
}
|
||
|
||
/** 优先使用后端结构化变更引用;仅有过期标记时展示全部当前关联素材,不能称其全部已变更。 */
|
||
export function referenceTargets(references: ShotReferences | null, issues: ProductionIssue[]): ReferenceTarget[] {
|
||
const changed = [
|
||
...new Set(
|
||
issues.filter(issue => issue.code === 'stale_keyframe').flatMap(issue => issue.missingSubjects ?? [])
|
||
)
|
||
]
|
||
const available = references?.references ?? []
|
||
const refs = changed.length
|
||
? changed
|
||
: [
|
||
...new Set([
|
||
...available.map(item => item.subjectRef),
|
||
...(references?.missing ?? []).map(item => item.subjectRef)
|
||
])
|
||
]
|
||
return refs.flatMap(ref => {
|
||
const matches = available.filter(item => item.subjectRef === ref || item.subjectId === ref)
|
||
if (matches.length)
|
||
return matches.map(item => ({
|
||
subjectRef: item.subjectRef,
|
||
subjectId: item.subjectId,
|
||
formId: item.subjectFormId,
|
||
label: `${item.subjectName} · ${item.subjectFormName}(${item.subjectRef})`
|
||
}))
|
||
const missing = references?.missing.find(item => item.subjectRef === ref || item.subjectId === ref)
|
||
return [
|
||
{
|
||
subjectRef: missing?.subjectRef ?? ref,
|
||
subjectId: missing?.subjectId,
|
||
label: `${missing?.subjectName ? `${missing.subjectName} · ` : ''}${ref}(当前形态待核对)`
|
||
}
|
||
]
|
||
})
|
||
}
|
||
|
||
/** 深链接保留来源镜头,图库据此读取实时状态而不是相信 URL 的过期标记。 */
|
||
export function referenceLocation(projectId: string, shotId: string, target: ReferenceTarget) {
|
||
return {
|
||
path: `/projects/${encodeURIComponent(projectId)}/subject-images`,
|
||
query: {
|
||
sourceShotId: shotId,
|
||
subjectRef: target.subjectRef,
|
||
...(target.formId ? { subjectFormId: target.formId } : {})
|
||
}
|
||
}
|
||
}
|
||
|
||
/** 从 URL 取单值查询参数,不接受多值数组或空白值。 */
|
||
export function queryText(value: unknown): string {
|
||
return typeof value === 'string' ? value.trim() : ''
|
||
}
|