Fix #230 slug album not downloading correctly

This commit is contained in:
Alan Grainger
2026-05-28 09:35:03 +08:00
parent 062c7bef19
commit 95957b7d37
3 changed files with 28 additions and 20 deletions
+8 -2
View File
@@ -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
}
/**
+10 -8
View File
@@ -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()
})
+10 -10
View File
@@ -209,7 +209,6 @@ class Render {
// Build structured items in parallel
const items: GalleryItem[] = await Promise.all(share.assets.map(async (asset): Promise<GalleryItem> => {
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 `<a download="...">` 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,