feat(short-drama-agent-front): 补齐后端生产与质量功能
This commit is contained in:
1 parent
967c4ebea1
commit
470b52e26d
52 files changed
+3754
-1075
No files matched your search
@@ -7,9 +7,89 @@ import type { DesignedShot, EpisodeDirections, EpisodeVisualStates, StoryboardSe
|
||||
/** 仅保存本会话回执和已返回的 Prompt,切换路由不丢失长请求结果。 */
|
||||
const sessions = reactive<Record<string, StoryboardSession>>({})
|
||||
|
||||
/**
|
||||
* 恢复整个项目已失效的剧集集合,兼容隐私模式或损坏的浏览器缓存。
|
||||
* @param projectId 正式项目 ID
|
||||
* @returns 只包含正整数剧集编号的失效标记
|
||||
*/
|
||||
function savedEpisodeInvalidations(projectId: string): Record<number, boolean> {
|
||||
try {
|
||||
if (typeof localStorage === 'undefined') return {}
|
||||
const value: unknown = JSON.parse(
|
||||
localStorage.getItem(`short-drama:storyboard-invalidated:${projectId}`) ?? '[]'
|
||||
)
|
||||
if (!Array.isArray(value)) return {}
|
||||
return Object.fromEntries(
|
||||
value
|
||||
.filter(number => typeof number === 'number' && Number.isSafeInteger(number) && number > 0)
|
||||
.map(number => [number, true])
|
||||
)
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取指定项目的独立回执容器。 */
|
||||
export function getStoryboardSession(id: string): StoryboardSession {
|
||||
return (sessions[id] ??= { receipt: null, prompts: {}, regeneratedEpisodes: {} })
|
||||
return (sessions[id] ??= {
|
||||
receipt: null,
|
||||
prompts: {},
|
||||
regeneratedEpisodes: {},
|
||||
invalidatedEpisodeSources: savedEpisodeInvalidations(id)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据真实有效终态废弃旧正文,并持久化全部剧集,隐藏任务不影响恢复。
|
||||
* @param projectId 正式项目 ID
|
||||
* @param episodeNo 已有效重生成的剧集编号
|
||||
*/
|
||||
export function invalidateEpisodeSource(projectId: string, episodeNo: number) {
|
||||
if (!Number.isSafeInteger(episodeNo) || episodeNo <= 0) return
|
||||
const session = getStoryboardSession(projectId)
|
||||
delete session.regeneratedEpisodes[episodeNo]
|
||||
session.invalidatedEpisodeSources = {
|
||||
...savedEpisodeInvalidations(projectId),
|
||||
...session.invalidatedEpisodeSources,
|
||||
[episodeNo]: true
|
||||
}
|
||||
try {
|
||||
if (typeof localStorage !== 'undefined')
|
||||
localStorage.setItem(
|
||||
`short-drama:storyboard-invalidated:${projectId}`,
|
||||
JSON.stringify(Object.keys(session.invalidatedEpisodeSources).map(Number))
|
||||
)
|
||||
} catch {
|
||||
/* 浏览器禁止存储时仍保留当前会话保护。 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅可信完整重新拆解完成后清除旧失效集合。
|
||||
* @param projectId 正式项目 ID
|
||||
*/
|
||||
export function clearEpisodeSourceInvalidations(projectId: string) {
|
||||
getStoryboardSession(projectId).invalidatedEpisodeSources = {}
|
||||
try {
|
||||
if (typeof localStorage !== 'undefined')
|
||||
localStorage.removeItem(`short-drama:storyboard-invalidated:${projectId}`)
|
||||
} catch {
|
||||
/* 当前会话已经清除,存储限制不会触发业务请求。 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重生成后不向新 Shot ID 回填旧 checkpoint 的标题、剧情或时长。
|
||||
* @param projectId 当前正式项目 ID
|
||||
* @param episodeNo 当前剧集编号
|
||||
* @param fallback 未失效的原始分集快照
|
||||
* @returns 实际正文或缺省;缺省时仅展示正式镜头编号
|
||||
*/
|
||||
export function currentEpisodeSource(projectId: string, episodeNo: number, fallback?: EpisodeShots) {
|
||||
const session = getStoryboardSession(projectId)
|
||||
return (
|
||||
session.regeneratedEpisodes[episodeNo] ?? (session.invalidatedEpisodeSources[episodeNo] ? undefined : fallback)
|
||||
)
|
||||
}
|
||||
|
||||
/** 后端生成服务只读取最新 Breakdown;不能用历史可恢复快照冒充当前生成前置条件。 */
|
||||
|
||||
Reference in new issue
Block a user