diff --git a/server/src/controllers/download.controller.ts b/server/src/controllers/download.controller.ts index 2bdf5c4837..e45eeb23f3 100644 --- a/server/src/controllers/download.controller.ts +++ b/server/src/controllers/download.controller.ts @@ -1,6 +1,5 @@ -import { Body, Controller, HttpCode, HttpStatus, Post, Res, StreamableFile } from '@nestjs/common'; +import { Body, Controller, HttpCode, HttpStatus, Post, StreamableFile } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; -import { Response } from 'express'; import { Endpoint, HistoryBuilder } from 'src/decorators'; import { AuthDto } from 'src/dtos/auth.dto'; import { DownloadArchiveDto, DownloadInfoDto, DownloadResponseDto } from 'src/dtos/download.dto'; @@ -36,16 +35,7 @@ export class DownloadController { 'Download a ZIP archive containing the specified assets. The assets must have been previously requested via the "getDownloadInfo" endpoint.', history: new HistoryBuilder().added('v1').beta('v1').stable('v2'), }) - downloadArchive( - @Res({ passthrough: true }) res: Response, - @Auth() auth: AuthDto, - @Body() dto: DownloadArchiveDto, - ): Promise { - if (dto.archiveName) { - res.set({ - 'Content-Disposition': `attachment; filename*=UTF-8''${encodeURIComponent(dto.archiveName)}.zip`, - }); - } + downloadArchive(@Auth() auth: AuthDto, @Body() dto: DownloadArchiveDto): Promise { return this.service.downloadArchive(auth, dto).then(asStreamableFile); } } diff --git a/server/src/repositories/storage.repository.ts b/server/src/repositories/storage.repository.ts index 9604372fbe..7ee74d9870 100644 --- a/server/src/repositories/storage.repository.ts +++ b/server/src/repositories/storage.repository.ts @@ -31,6 +31,7 @@ export interface WatchEvents { export interface ImmichReadStream { stream: Readable; type?: string; + disposition?: string | string[]; length?: number; } diff --git a/server/src/services/download.service.ts b/server/src/services/download.service.ts index 3dc9c0dd03..c73da19543 100644 --- a/server/src/services/download.service.ts +++ b/server/src/services/download.service.ts @@ -117,6 +117,9 @@ export class DownloadService extends BaseService { void zip.finalize(); - return { stream: zip.stream }; + return { + stream: zip.stream, + disposition: dto.archiveName && `attachment; filename*=UTF-8''${encodeURIComponent(dto.archiveName)}.zip`, + }; } } diff --git a/server/src/utils/file.ts b/server/src/utils/file.ts index 24d555f2fe..df3a0ce3e9 100644 --- a/server/src/utils/file.ts +++ b/server/src/utils/file.ts @@ -86,6 +86,6 @@ export const sendFile = async ( } }; -export const asStreamableFile = ({ stream, type, length }: ImmichReadStream) => { - return new StreamableFile(stream, { type, length }); +export const asStreamableFile = ({ stream, type, disposition, length }: ImmichReadStream) => { + return new StreamableFile(stream, { type, disposition, length }); };