mirror of
https://github.com/immich-app/immich.git
synced 2025-06-03 05:36:44 -04:00
106 lines
3.0 KiB
TypeScript
106 lines
3.0 KiB
TypeScript
import { Body, Controller, Get, Next, Param, Post, Put, Query, Res } from '@nestjs/common';
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
import { NextFunction, Response } from 'express';
|
|
import { BulkIdResponseDto } from 'src/dtos/asset-ids.response.dto';
|
|
import { AssetResponseDto } from 'src/dtos/asset-response.dto';
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
|
import {
|
|
AssetFaceUpdateDto,
|
|
MergePersonDto,
|
|
PeopleResponseDto,
|
|
PeopleUpdateDto,
|
|
PersonCreateDto,
|
|
PersonResponseDto,
|
|
PersonSearchDto,
|
|
PersonStatisticsResponseDto,
|
|
PersonUpdateDto,
|
|
} from 'src/dtos/person.dto';
|
|
import { Auth, Authenticated, FileResponse } from 'src/middleware/auth.guard';
|
|
import { PersonService } from 'src/services/person.service';
|
|
import { sendFile } from 'src/utils/file';
|
|
import { UUIDParamDto } from 'src/validation';
|
|
|
|
@ApiTags('Person')
|
|
@Controller('person')
|
|
export class PersonController {
|
|
constructor(private service: PersonService) {}
|
|
|
|
@Get()
|
|
@Authenticated()
|
|
getAllPeople(@Auth() auth: AuthDto, @Query() withHidden: PersonSearchDto): Promise<PeopleResponseDto> {
|
|
return this.service.getAll(auth, withHidden);
|
|
}
|
|
|
|
@Post()
|
|
@Authenticated()
|
|
createPerson(@Auth() auth: AuthDto, @Body() dto: PersonCreateDto): Promise<PersonResponseDto> {
|
|
return this.service.create(auth, dto);
|
|
}
|
|
|
|
@Put()
|
|
@Authenticated()
|
|
updatePeople(@Auth() auth: AuthDto, @Body() dto: PeopleUpdateDto): Promise<BulkIdResponseDto[]> {
|
|
return this.service.updateAll(auth, dto);
|
|
}
|
|
|
|
@Get(':id')
|
|
@Authenticated()
|
|
getPerson(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<PersonResponseDto> {
|
|
return this.service.getById(auth, id);
|
|
}
|
|
|
|
@Put(':id')
|
|
@Authenticated()
|
|
updatePerson(
|
|
@Auth() auth: AuthDto,
|
|
@Param() { id }: UUIDParamDto,
|
|
@Body() dto: PersonUpdateDto,
|
|
): Promise<PersonResponseDto> {
|
|
return this.service.update(auth, id, dto);
|
|
}
|
|
|
|
@Get(':id/statistics')
|
|
@Authenticated()
|
|
getPersonStatistics(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<PersonStatisticsResponseDto> {
|
|
return this.service.getStatistics(auth, id);
|
|
}
|
|
|
|
@Get(':id/thumbnail')
|
|
@FileResponse()
|
|
@Authenticated()
|
|
async getPersonThumbnail(
|
|
@Res() res: Response,
|
|
@Next() next: NextFunction,
|
|
@Auth() auth: AuthDto,
|
|
@Param() { id }: UUIDParamDto,
|
|
) {
|
|
await sendFile(res, next, () => this.service.getThumbnail(auth, id));
|
|
}
|
|
|
|
@Get(':id/assets')
|
|
@Authenticated()
|
|
getPersonAssets(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<AssetResponseDto[]> {
|
|
return this.service.getAssets(auth, id);
|
|
}
|
|
|
|
@Put(':id/reassign')
|
|
@Authenticated()
|
|
reassignFaces(
|
|
@Auth() auth: AuthDto,
|
|
@Param() { id }: UUIDParamDto,
|
|
@Body() dto: AssetFaceUpdateDto,
|
|
): Promise<PersonResponseDto[]> {
|
|
return this.service.reassignFaces(auth, id, dto);
|
|
}
|
|
|
|
@Post(':id/merge')
|
|
@Authenticated()
|
|
mergePerson(
|
|
@Auth() auth: AuthDto,
|
|
@Param() { id }: UUIDParamDto,
|
|
@Body() dto: MergePersonDto,
|
|
): Promise<BulkIdResponseDto[]> {
|
|
return this.service.mergePerson(auth, id, dto);
|
|
}
|
|
}
|