mirror of
https://github.com/immich-app/immich.git
synced 2025-05-30 19:54:52 -04:00
* Refactor controller methods, non-breaking change * Remove getAllAssets * used imports * sync:sql * missing mock * Removing remaining references * chore: remove unused code --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
95 lines
2.8 KiB
TypeScript
95 lines
2.8 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
HttpCode,
|
|
HttpStatus,
|
|
Inject,
|
|
Param,
|
|
ParseFilePipe,
|
|
Post,
|
|
Put,
|
|
Res,
|
|
UploadedFiles,
|
|
UseInterceptors,
|
|
} from '@nestjs/common';
|
|
import { ApiConsumes, ApiTags } from '@nestjs/swagger';
|
|
import { Response } from 'express';
|
|
import { EndpointLifecycle } from 'src/decorators';
|
|
import {
|
|
AssetBulkUploadCheckResponseDto,
|
|
AssetMediaResponseDto,
|
|
AssetMediaStatusEnum,
|
|
CheckExistingAssetsResponseDto,
|
|
} from 'src/dtos/asset-media-response.dto';
|
|
import {
|
|
AssetBulkUploadCheckDto,
|
|
AssetMediaReplaceDto,
|
|
CheckExistingAssetsDto,
|
|
UploadFieldName,
|
|
} from 'src/dtos/asset-media.dto';
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
|
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
|
import { Auth, Authenticated } from 'src/middleware/auth.guard';
|
|
import { FileUploadInterceptor, Route, UploadFiles, getFiles } from 'src/middleware/file-upload.interceptor';
|
|
import { AssetMediaService } from 'src/services/asset-media.service';
|
|
import { FileNotEmptyValidator, UUIDParamDto } from 'src/validation';
|
|
|
|
@ApiTags('Asset')
|
|
@Controller(Route.ASSET)
|
|
export class AssetMediaController {
|
|
constructor(
|
|
@Inject(ILoggerRepository) private logger: ILoggerRepository,
|
|
private service: AssetMediaService,
|
|
) {}
|
|
|
|
/**
|
|
* Replace the asset with new file, without changing its id
|
|
*/
|
|
@Put(':id/file')
|
|
@UseInterceptors(FileUploadInterceptor)
|
|
@ApiConsumes('multipart/form-data')
|
|
@Authenticated({ sharedLink: true })
|
|
@EndpointLifecycle({ addedAt: 'v1.106.0' })
|
|
async replaceAsset(
|
|
@Auth() auth: AuthDto,
|
|
@Param() { id }: UUIDParamDto,
|
|
@UploadedFiles(new ParseFilePipe({ validators: [new FileNotEmptyValidator([UploadFieldName.ASSET_DATA])] }))
|
|
files: UploadFiles,
|
|
@Body() dto: AssetMediaReplaceDto,
|
|
@Res({ passthrough: true }) res: Response,
|
|
): Promise<AssetMediaResponseDto> {
|
|
const { file } = getFiles(files);
|
|
const responseDto = await this.service.replaceAsset(auth, id, dto, file);
|
|
if (responseDto.status === AssetMediaStatusEnum.DUPLICATE) {
|
|
res.status(HttpStatus.OK);
|
|
}
|
|
return responseDto;
|
|
}
|
|
|
|
/**
|
|
* Checks if multiple assets exist on the server and returns all existing - used by background backup
|
|
*/
|
|
@Post('exist')
|
|
@HttpCode(HttpStatus.OK)
|
|
@Authenticated()
|
|
checkExistingAssets(
|
|
@Auth() auth: AuthDto,
|
|
@Body() dto: CheckExistingAssetsDto,
|
|
): Promise<CheckExistingAssetsResponseDto> {
|
|
return this.service.checkExistingAssets(auth, dto);
|
|
}
|
|
|
|
/**
|
|
* Checks if assets exist by checksums
|
|
*/
|
|
@Post('bulk-upload-check')
|
|
@HttpCode(HttpStatus.OK)
|
|
@Authenticated()
|
|
checkBulkUpload(
|
|
@Auth() auth: AuthDto,
|
|
@Body() dto: AssetBulkUploadCheckDto,
|
|
): Promise<AssetBulkUploadCheckResponseDto> {
|
|
return this.service.bulkUploadCheck(auth, dto);
|
|
}
|
|
}
|