43 lines
2.3 KiB
TypeScript
43 lines
2.3 KiB
TypeScript
import { computed, type Ref } from 'vue'
|
|
import { useQuery } from '../../composables/useQuery'
|
|
import { productionApi } from '../production/api'
|
|
import { useShotReferences } from '../production/useShotReferences'
|
|
|
|
/** 镜头影响检查与素材查询独立;检查失败不把素材误判为正常或阻断独立的素材操作。 */
|
|
export function useKeyframeImpact(projectId: Ref<string>, sourceShotId: Ref<string>) {
|
|
const query = useQuery(projectId, async (id, signal) => {
|
|
if (!id) return null
|
|
const [keyframes, videos] = await Promise.all([
|
|
productionApi.keyframeReadiness(id, false, signal),
|
|
productionApi.videoReadiness(id, false, signal)
|
|
])
|
|
if (!keyframes || !Array.isArray(keyframes.items) || !videos || !Array.isArray(videos.items))
|
|
throw new Error('主首帧影响检查未返回镜头列表。')
|
|
const byShot = new Map(videos.items.map(item => [item.shotId, item]))
|
|
if (byShot.size !== keyframes.items.length || keyframes.items.some(item => !byShot.has(item.shotId)))
|
|
throw new Error('首帧与视频检查的镜头列表不一致,可能正在重新拆解,请刷新后重试。')
|
|
return {
|
|
...keyframes,
|
|
items: keyframes.items.map(item => {
|
|
const issues = byShot.get(item.shotId)?.issues.filter(issue => issue.code === 'stale_keyframe') ?? []
|
|
return {
|
|
...item,
|
|
primaryKeyframeStale: !!item.primaryKeyframeStale || issues.length > 0,
|
|
inconsistent: item.primaryKeyframeStale === false && issues.length > 0
|
|
}
|
|
})
|
|
}
|
|
})
|
|
const stale = computed(() => query.data.value?.items.filter(item => item.primaryKeyframeStale) ?? [])
|
|
// 不根据 URL 中的任意镜头 ID 发请求,必须属于当前项目的就绪列表。
|
|
const source = computed(() => query.data.value?.items.find(item => item.shotId === sourceShotId.value))
|
|
const references = useShotReferences(
|
|
projectId,
|
|
computed(() => source.value?.shotId ?? '')
|
|
)
|
|
const relatedForms = computed(
|
|
() => new Set(references.data.value?.references.map(item => item.subjectFormId) ?? [])
|
|
)
|
|
return { query, stale, source, references, relatedForms }
|
|
}
|