auto-save 2026-05-13 23:29 (~5)

This commit is contained in:
2026-05-13 23:29:35 +08:00
parent 38091d318b
commit 03770b1ed8
5 changed files with 108 additions and 7 deletions

View File

@@ -16,7 +16,7 @@ import { ThemeToggle } from "@/components/theme-toggle"
import { StoryboardBar } from "@/components/storyboard-bar"
import { StoryboardWorkbench } from "@/components/storyboard-workbench"
import {
addManualFrame, analyzeJob, createJob, getJob, uploadJob, deleteFrame, deleteGeneratedImage,
addManualFrame, analyzeJob, createJob, getJob, listJobs, uploadJob, deleteFrame, deleteGeneratedImage,
deleteGeneratedVideo, generateStoryboardVideo,
type Job, type ImageRef, type StoryboardScene,
} from "@/lib/api"
@@ -321,19 +321,29 @@ export default function Home() {
}
}, [job, selectedFrames, setJob])
// URL ?job=xxx,yyy 自动恢复多个 job
// 启动恢复:URL ?job=xxx,yyy 优先;否则从后端拉全部历史(按 mtime 倒序,最新放末尾)
useEffect(() => {
const params = new URLSearchParams(window.location.search)
const idsStr = params.get("job") ?? ""
const ids = idsStr.split(",").filter(Boolean)
if (ids.length === 0) return
Promise.all(ids.map((id) => getJob(id).catch(() => null))).then((results) => {
const ids = (params.get("job") ?? "").split(",").filter(Boolean)
const restore = async () => {
let targetIds = ids
if (targetIds.length === 0) {
try {
const list = await listJobs()
targetIds = list.map((s) => s.id).reverse()
} catch {
return
}
}
if (targetIds.length === 0) return
const results = await Promise.all(targetIds.map((id) => getJob(id).catch(() => null)))
const valid = results.filter((j): j is Job => !!j)
if (valid.length > 0) {
setJobs(valid)
setActiveJobId(valid[valid.length - 1].id)
}
})
}
void restore()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])