auto-save 2026-05-19 11:29 (~6)

This commit is contained in:
2026-05-19 11:31:13 +08:00
parent 74148d0d05
commit 65a9080e02
6 changed files with 124 additions and 29 deletions

View File

@@ -136,7 +136,7 @@ export default function Home() {
const r = await fetch('/api/packs/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sessionId: current.id, imageId: image.id, kind }),
body: JSON.stringify({ sessionId: current.id, imageId: image.id, kind, background: true }),
});
if (!r.ok) {
alert('素材包生成失败:' + (await r.text()));
@@ -147,6 +147,7 @@ export default function Home() {
const all = await refreshSessions();
const updated = all.find(x => x.id === current.id) ?? null;
setCurrent(updated);
scheduleSessionRefresh(current.id);
} finally {
setLoadingKind(null);
}
@@ -159,6 +160,15 @@ export default function Home() {
return updated;
}
function scheduleSessionRefresh(sessionId: string, remaining = 90) {
if (remaining <= 0) return;
window.setTimeout(async () => {
const updated = await reloadCurrent(sessionId);
const hasDraftPack = updated?.packs?.some(pack => pack.status === 'draft') ?? false;
if (hasDraftPack || remaining > 84) scheduleSessionRefresh(sessionId, remaining - 1);
}, 5000);
}
async function handleLockCharacter(image: GenImage) {
if (!current || characterLoading) return;
setCharacterLoading(true);
@@ -187,7 +197,7 @@ export default function Home() {
const r = await fetch('/api/packs/generate-all', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sessionId: current.id, imageId: image.id }),
body: JSON.stringify({ sessionId: current.id, imageId: image.id, background: true }),
});
if (!r.ok) {
alert('完整三包生成失败:' + (await r.text()));
@@ -196,6 +206,7 @@ export default function Home() {
const d: GenerateAllPacksResponse = await r.json();
setProvider(d.provider);
await reloadCurrent(current.id);
scheduleSessionRefresh(current.id);
} finally {
setAllLoading(false);
}