Improve image download timeout handling

This commit is contained in:
Samuel Newman
2025-10-26 21:58:32 +02:00
parent 2a4b825637
commit 88adf9bcbd
+10 -3
View File
@@ -378,14 +378,21 @@ function createPath(ext: string) {
async function downloadImage(uri: string, path: string, timeout: number) {
const dlResumable = createDownloadResumable(uri, path, {cache: true})
const to1 = setTimeout(() => dlResumable.cancelAsync(), timeout)
let timedOut = false
const to1 = setTimeout(() => {
timedOut = true
dlResumable.cancelAsync()
}, timeout)
const dlRes = await dlResumable.downloadAsync()
clearTimeout(to1)
if (!dlRes?.uri) {
throw new Error('Failed to download image - dlRes is undefined')
if (timedOut) {
throw new Error('Failed to download image - timed out')
} else {
throw new Error('Failed to download image - dlRes is undefined')
}
}
return normalizePath(dlRes.uri)