diff --git a/app/src/immich.ts b/app/src/immich.ts index 1a8e856..6cf9b3b 100644 --- a/app/src/immich.ts +++ b/app/src/immich.ts @@ -344,8 +344,14 @@ class Immich { * user gets when they hit "download". */ requiresOriginal (asset: Asset): boolean { - return asset.type === AssetType.video || - asset.originalMimeType === 'image/gif' + if (asset.type === AssetType.video) { + return true + } else if (asset.originalMimeType?.startsWith('video/')) { + return true + } else if (asset.originalMimeType === 'image/gif') { + return true + } + return false } /** diff --git a/app/src/index.ts b/app/src/index.ts index b9bc6bd..59b4d63 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -200,23 +200,25 @@ app.get('/share/:type(photo|video)/:key/:id/:size?', decodeCookie, async (req, r return } - // Verify the requested asset belongs to this share link - const assetBelongsToShare = share.link?.assets?.some(a => a.id === req.params.id) - if (!assetBelongsToShare) { + // Find the real asset on the share so assetBuffer has access to + // originalMimeType and originalFileName (needed for Content-Disposition and + // for requiresOriginal to recognise videos/animated images and bypass the + // preview downgrade). Doubles as the "belongs to this share" check. + const realAsset = share.link?.assets?.find(a => a.id === req.params.id) + if (!realAsset) { respondToInvalidRequest(res, 404, 'Asset not found in share') return } + const asset: Asset = { + ...realAsset, + type: req.params.type === 'video' ? AssetType.video : AssetType.image + } const request = { req, key: req.params.key, range: req.headers.range || '' } - const asset = { - id: req.params.id, - key: req.params.key, - type: req.params.type === 'video' ? AssetType.video : AssetType.image - } as Asset render.assetBuffer(request, res, asset, req.params.size).then() }) diff --git a/app/src/render.ts b/app/src/render.ts index 9da7a96..679b12c 100644 --- a/app/src/render.ts +++ b/app/src/render.ts @@ -209,7 +209,6 @@ class Render { // Build structured items in parallel const items: GalleryItem[] = await Promise.all(share.assets.map(async (asset): Promise => { let videoData: string | undefined - let downloadUrl: string | undefined if (asset.type === AssetType.video) { videoData = JSON.stringify({ source: [ @@ -224,14 +223,15 @@ class Render { } }) } - // Download is offered when the operator allows full-resolution downloads, - // or when the asset is one that has to come from /original to be useful - // (video, animated image — see immich.requiresOriginal). - if (getConfigOption('ipp.downloadOriginalPhoto', true) || immich.requiresOriginal(asset)) { - downloadUrl = asset.type === AssetType.video - ? immich.videoUrl(share.key, asset.id) - : immich.photoUrl(share.key, asset.id, ImageSize.original) - } + + // Compute the filename so the client-side `` attribute + // matches the bytes the server will return. Without this, a HEIC + // original served as a preview JPEG would download as "photo.heic" + // with JPEG bytes inside. + const downloadUrl = immich.photoUrl(share.key, asset.id, ImageSize.original) + const downloadServedSize = (getConfigOption('ipp.downloadOriginalPhoto', true) || immich.requiresOriginal(asset)) + ? ImageSize.original + : ImageSize.preview const thumbnailUrl = immich.photoUrl(share.key, asset.id, ImageSize.thumbnail) const previewUrl = immich.photoUrl(share.key, asset.id, immich.getPreviewImageSize(asset)) @@ -254,7 +254,7 @@ class Render { downloadUrl, videoData, description: description || undefined, - downloadFilename: this.getFilename(asset), + downloadFilename: this.getFilename(asset, downloadServedSize), width, height, thumbhash: asset.thumbhash,