Merge PR #281: fall back to video playback for downloads on download-disabled shares

This commit is contained in:
Alan Grainger
2026-08-20 07:31:59 +12:00
6 changed files with 89 additions and 23 deletions
+7 -7
View File
@@ -1,6 +1,6 @@
import { assetFetchUrl, authHeadersForAsset } from '../immich'
import { Response } from 'express-serve-static-core'
import { Asset, ImageSize, SharedLink } from '../types'
import { Asset, SharedLink } from '../types'
import { getNumericConfigOption } from '../config/access'
import { log } from '../utils/log'
import archiver, { Archiver } from 'archiver'
@@ -10,7 +10,7 @@ import { pipeline } from 'stream/promises'
import { promises as fs, createWriteStream } from 'fs'
import { tmpdir } from 'os'
import { join } from 'path'
import { resolveImageEndpoint, ImageEndpoint } from '../gallery/sizing'
import { resolveDownloadEndpoint, ImageEndpoint } from '../gallery/sizing'
import { title } from '../share'
import { getFilename } from '../gallery/filename'
import { createLimiter } from '../utils/limiter'
@@ -114,7 +114,7 @@ export async function downloadAssets (res: Response, share: SharedLink, assets:
})
try {
const stages = stageAssetsToDisk(assets, options, controller.signal)
const stages = stageAssetsToDisk(share, assets, options, controller.signal)
const failure = await archiveStaged(archive, stages, controller)
if (clientGone) {
log(`Zip download for share ${share.key} cancelled by client`)
@@ -148,9 +148,9 @@ export async function downloadAssets (res: Response, share: SharedLink, assets:
* concurrently. Returns the promise array in input order so the consumer can
* archive in order.
*/
function stageAssetsToDisk (assets: Asset[], options: StagingOptions, signal: AbortSignal): Promise<StageOutcome>[] {
function stageAssetsToDisk (share: SharedLink, assets: Asset[], options: StagingOptions, signal: AbortSignal): Promise<StageOutcome>[] {
const limit = createLimiter(options.concurrency)
return assets.map((asset, index) => limit(() => stageOne(asset, index, options, signal)))
return assets.map((asset, index) => limit(() => stageOne(share, asset, index, options, signal)))
}
/**
@@ -199,10 +199,10 @@ function abortDownload (archive: Archiver, res: Response, share: SharedLink, fai
* Returns the staged asset on success, a wrapped Failure on error, or null
* if we observed the abort flag and bailed without doing work.
*/
async function stageOne (asset: Asset, index: number, options: StagingOptions, signal: AbortSignal): Promise<StageOutcome> {
async function stageOne (share: SharedLink, asset: Asset, index: number, options: StagingOptions, signal: AbortSignal): Promise<StageOutcome> {
if (signal.aborted) return null
const endpoint = resolveImageEndpoint(ImageSize.original, asset)
const endpoint = resolveDownloadEndpoint(asset, share.allowDownload !== false)
const url = assetFetchUrl(asset, endpoint.subpath, endpoint.sizeQueryParam)
const reqAuthHeaders = await authHeadersForAsset(asset)