refactor(vtt-thumbnail): [PKG-VTT-THUMB-04] type runtime data and resource boundaries

This commit is contained in:
Harvey Zhao committed 2026-09-13 09:03:20 +08:00
1 parent 80588a3046
commit 7f2906ae52
22 files changed
+2940 -75

No files matched your search

@@ -0,0 +1,23 @@
import type { Lifetime } from './types'
export default async function requestVtt(url = '', lifetime: Lifetime): Promise<string | void> {
if (lifetime.closed)
return
const controller = typeof AbortController === 'function' ? new AbortController() : null
const release = lifetime.own(() => controller?.abort())
try {
if (lifetime.closed)
return
const response = await lifetime.wait(controller ? fetch(url, { signal: controller.signal }) : fetch(url))
if (lifetime.closed)
return
if (response!.ok === false)
throw new Error(`Failed to fetch VTT thumbnails: HTTP ${response!.status}`)
if (lifetime.closed)
return
return await lifetime.wait(response!.text())
}
finally {
release()
}
}