mirror of
https://github.com/immich-app/immich
synced 2026-08-15 13:03:57 +00:00
refactor: move content-disposition to ImmichReadStream
This commit is contained in:
parent
1f2d566be0
commit
d1f61de51d
4 changed files with 9 additions and 15 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ export interface WatchEvents {
|
|||
export interface ImmichReadStream {
|
||||
stream: Readable;
|
||||
type?: string;
|
||||
disposition?: string | string[];
|
||||
length?: number;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue