Fix #230 slug album not downloading correctly
This commit is contained in:
+8
-2
@@ -344,8 +344,14 @@ class Immich {
|
|||||||
* user gets when they hit "download".
|
* user gets when they hit "download".
|
||||||
*/
|
*/
|
||||||
requiresOriginal (asset: Asset): boolean {
|
requiresOriginal (asset: Asset): boolean {
|
||||||
return asset.type === AssetType.video ||
|
if (asset.type === AssetType.video) {
|
||||||
asset.originalMimeType === 'image/gif'
|
return true
|
||||||
|
} else if (asset.originalMimeType?.startsWith('video/')) {
|
||||||
|
return true
|
||||||
|
} else if (asset.originalMimeType === 'image/gif') {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+10
-8
@@ -200,23 +200,25 @@ app.get('/share/:type(photo|video)/:key/:id/:size?', decodeCookie, async (req, r
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the requested asset belongs to this share link
|
// Find the real asset on the share so assetBuffer has access to
|
||||||
const assetBelongsToShare = share.link?.assets?.some(a => a.id === req.params.id)
|
// originalMimeType and originalFileName (needed for Content-Disposition and
|
||||||
if (!assetBelongsToShare) {
|
// 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')
|
respondToInvalidRequest(res, 404, 'Asset not found in share')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const asset: Asset = {
|
||||||
|
...realAsset,
|
||||||
|
type: req.params.type === 'video' ? AssetType.video : AssetType.image
|
||||||
|
}
|
||||||
|
|
||||||
const request = {
|
const request = {
|
||||||
req,
|
req,
|
||||||
key: req.params.key,
|
key: req.params.key,
|
||||||
range: req.headers.range || ''
|
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()
|
render.assetBuffer(request, res, asset, req.params.size).then()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -209,7 +209,6 @@ class Render {
|
|||||||
// Build structured items in parallel
|
// Build structured items in parallel
|
||||||
const items: GalleryItem[] = await Promise.all(share.assets.map(async (asset): Promise<GalleryItem> => {
|
const items: GalleryItem[] = await Promise.all(share.assets.map(async (asset): Promise<GalleryItem> => {
|
||||||
let videoData: string | undefined
|
let videoData: string | undefined
|
||||||
let downloadUrl: string | undefined
|
|
||||||
if (asset.type === AssetType.video) {
|
if (asset.type === AssetType.video) {
|
||||||
videoData = JSON.stringify({
|
videoData = JSON.stringify({
|
||||||
source: [
|
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
|
// Compute the filename so the client-side `<a download="...">` attribute
|
||||||
// (video, animated image — see immich.requiresOriginal).
|
// matches the bytes the server will return. Without this, a HEIC
|
||||||
if (getConfigOption('ipp.downloadOriginalPhoto', true) || immich.requiresOriginal(asset)) {
|
// original served as a preview JPEG would download as "photo.heic"
|
||||||
downloadUrl = asset.type === AssetType.video
|
// with JPEG bytes inside.
|
||||||
? immich.videoUrl(share.key, asset.id)
|
const downloadUrl = immich.photoUrl(share.key, asset.id, ImageSize.original)
|
||||||
: 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 thumbnailUrl = immich.photoUrl(share.key, asset.id, ImageSize.thumbnail)
|
||||||
const previewUrl = immich.photoUrl(share.key, asset.id, immich.getPreviewImageSize(asset))
|
const previewUrl = immich.photoUrl(share.key, asset.id, immich.getPreviewImageSize(asset))
|
||||||
@@ -254,7 +254,7 @@ class Render {
|
|||||||
downloadUrl,
|
downloadUrl,
|
||||||
videoData,
|
videoData,
|
||||||
description: description || undefined,
|
description: description || undefined,
|
||||||
downloadFilename: this.getFilename(asset),
|
downloadFilename: this.getFilename(asset, downloadServedSize),
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
thumbhash: asset.thumbhash,
|
thumbhash: asset.thumbhash,
|
||||||
|
|||||||
Reference in New Issue
Block a user