refactor: move content-disposition to ImmichReadStream

This commit is contained in:
Diogo Correia 2026-07-28 16:05:15 +01:00
parent 1f2d566be0
commit d1f61de51d
No known key found for this signature in database
GPG key ID: 7B5273B10C4495CF
4 changed files with 9 additions and 15 deletions

View file

@ -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<StreamableFile> {
if (dto.archiveName) {
res.set({
'Content-Disposition': `attachment; filename*=UTF-8''${encodeURIComponent(dto.archiveName)}.zip`,
});
}
downloadArchive(@Auth() auth: AuthDto, @Body() dto: DownloadArchiveDto): Promise<StreamableFile> {
return this.service.downloadArchive(auth, dto).then(asStreamableFile);
}
}

View file

@ -31,6 +31,7 @@ export interface WatchEvents {
export interface ImmichReadStream {
stream: Readable;
type?: string;
disposition?: string | string[];
length?: number;
}

View file

@ -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`,
};
}
}

View file

@ -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 });
};