Add timeout for image fetch
This commit is contained in:
+4
-5
@@ -226,8 +226,8 @@ class Render {
|
|||||||
* instead of a zip that's quietly missing files.
|
* instead of a zip that's quietly missing files.
|
||||||
*/
|
*/
|
||||||
async downloadAssets (res: Response, share: SharedLink, assets: Asset[]) {
|
async downloadAssets (res: Response, share: SharedLink, assets: Asset[]) {
|
||||||
const downloadOriginalAsset = getConfigOption('ipp.downloadOriginalPhoto', true)
|
|
||||||
const concurrency = Math.max(1, getConfigOption('ipp.downloadFromImmichConcurrencyLimit', 8) as number)
|
const concurrency = Math.max(1, getConfigOption('ipp.downloadFromImmichConcurrencyLimit', 8) as number)
|
||||||
|
const endpoint = this.resolveImageEndpoint(ImageSize.original)
|
||||||
res.setHeader('Content-Type', 'application/zip')
|
res.setHeader('Content-Type', 'application/zip')
|
||||||
let filename = (sanitize(this.title(share)) || 'photos') + '.zip'
|
let filename = (sanitize(this.title(share)) || 'photos') + '.zip'
|
||||||
filename = encodeURI(filename)
|
filename = encodeURI(filename)
|
||||||
@@ -251,11 +251,10 @@ class Render {
|
|||||||
if (aborted) return
|
if (aborted) return
|
||||||
const asset = queue.shift()
|
const asset = queue.shift()
|
||||||
if (!asset) return
|
if (!asset) return
|
||||||
const endpoint = downloadOriginalAsset ? 'original' : 'thumbnail'
|
const url = immich.buildUrl(immich.apiUrl() + '/assets/' + encodeURIComponent(asset.id) + endpoint.subpath, {
|
||||||
const url = immich.buildUrl(immich.apiUrl() + '/assets/' + encodeURIComponent(asset.id) + '/' + endpoint, {
|
|
||||||
key: asset.key,
|
key: asset.key,
|
||||||
password: asset.password,
|
password: asset.password,
|
||||||
size: downloadOriginalAsset ? '' : 'preview'
|
size: endpoint.sizeQueryParam
|
||||||
})
|
})
|
||||||
|
|
||||||
let buffer: Buffer | undefined
|
let buffer: Buffer | undefined
|
||||||
@@ -264,7 +263,7 @@ class Render {
|
|||||||
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
||||||
if (aborted) return
|
if (aborted) return
|
||||||
try {
|
try {
|
||||||
const data = await fetch(url)
|
const data = await fetch(url, { signal: AbortSignal.timeout(20_000) })
|
||||||
if (data.ok) {
|
if (data.ok) {
|
||||||
buffer = Buffer.from(await data.arrayBuffer())
|
buffer = Buffer.from(await data.arrayBuffer())
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user