feat: move unified generation to background worker

This commit is contained in:
2026-04-19 17:29:37 +08:00
parent 5318de670f
commit 6fb128955f
15 changed files with 632 additions and 285 deletions

View File

@@ -67,6 +67,7 @@ const audioDuration = ref(0)
const error = ref('')
const showDeleteConfirm = ref(false)
const generationTraceRef = ref<InstanceType<typeof GenerationTrace> | null>(null)
let refreshTimer: ReturnType<typeof setInterval> | null = null
const storyParagraphs = computed(() => story.value?.story_text?.split('\n\n') ?? [])
const generationMeta = computed(() => getGenerationStatusMeta(story.value?.generation_status))
@@ -75,6 +76,7 @@ const audioMeta = computed(() => getAssetStatusMeta(story.value?.audio_status))
const canRetryImage = computed(() => story.value?.retryable_assets.includes('image') ?? false)
const canRetryAudio = computed(() => story.value?.retryable_assets.includes('audio') ?? false)
const isAudioGenerating = computed(() => story.value?.audio_status === 'generating')
const shouldAutoRefreshStory = computed(() => story.value?.generation_status === 'assets_generating')
const audioCacheLabel = computed(() => {
if (!audioCacheStatus.value?.cache_exists) return '暂无缓存'
const size = audioCacheStatus.value.cache_size_bytes ?? 0
@@ -109,6 +111,13 @@ async function refreshStorySnapshot() {
await refreshAudioStatus().catch(() => undefined)
}
function stopAutoRefresh() {
if (refreshTimer) {
clearInterval(refreshTimer)
refreshTimer = null
}
}
async function fetchStory() {
loading.value = true
error.value = ''
@@ -283,7 +292,19 @@ watch(
{ immediate: true },
)
watch(shouldAutoRefreshStory, (enabled) => {
stopAutoRefresh()
if (enabled) {
refreshTimer = setInterval(() => {
if (!loading.value && !imageLoading.value && !audioLoading.value) {
void refreshStorySnapshot().catch(() => undefined)
}
}, 2500)
}
})
onUnmounted(() => {
stopAutoRefresh()
if (audioUrl.value) {
URL.revokeObjectURL(audioUrl.value)
}