mirror of
https://github.com/immich-app/immich.git
synced 2025-11-29 14:39:48 +09:00
chore: move controllers and middleware (#8119)
This commit is contained in:
44
server/src/controllers/download.controller.ts
Normal file
44
server/src/controllers/download.controller.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Body, Controller, HttpCode, HttpStatus, Next, Param, Post, Res, StreamableFile } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { NextFunction, Response } from 'express';
|
||||
import { AssetIdsDto } from 'src/domain/asset/dto/asset-ids.dto';
|
||||
import { AuthDto } from 'src/domain/auth/auth.dto';
|
||||
import { DownloadInfoDto, DownloadResponseDto } from 'src/domain/download/download.dto';
|
||||
import { DownloadService } from 'src/domain/download/download.service';
|
||||
import { asStreamableFile, sendFile } from 'src/immich/app.utils';
|
||||
import { Auth, Authenticated, FileResponse, SharedLinkRoute } from 'src/middleware/auth.guard';
|
||||
import { UUIDParamDto } from 'src/validation';
|
||||
|
||||
@ApiTags('Download')
|
||||
@Controller('download')
|
||||
@Authenticated()
|
||||
export class DownloadController {
|
||||
constructor(private service: DownloadService) {}
|
||||
|
||||
@SharedLinkRoute()
|
||||
@Post('info')
|
||||
getDownloadInfo(@Auth() auth: AuthDto, @Body() dto: DownloadInfoDto): Promise<DownloadResponseDto> {
|
||||
return this.service.getDownloadInfo(auth, dto);
|
||||
}
|
||||
|
||||
@SharedLinkRoute()
|
||||
@Post('archive')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@FileResponse()
|
||||
downloadArchive(@Auth() auth: AuthDto, @Body() dto: AssetIdsDto): Promise<StreamableFile> {
|
||||
return this.service.downloadArchive(auth, dto).then(asStreamableFile);
|
||||
}
|
||||
|
||||
@SharedLinkRoute()
|
||||
@Post('asset/:id')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@FileResponse()
|
||||
async downloadFile(
|
||||
@Res() res: Response,
|
||||
@Next() next: NextFunction,
|
||||
@Auth() auth: AuthDto,
|
||||
@Param() { id }: UUIDParamDto,
|
||||
) {
|
||||
await sendFile(res, next, () => this.service.downloadFile(auth, id));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user