immich/server/src/immich/controllers/person.controller.ts

73 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-05-17 13:07:17 -04:00
import {
AssetResponseDto,
AuthUserDto,
BulkIdResponseDto,
2023-05-17 13:07:17 -04:00
ImmichReadStream,
MergePersonDto,
PeopleResponseDto,
2023-05-17 13:07:17 -04:00
PersonResponseDto,
PersonSearchDto,
2023-05-17 13:07:17 -04:00
PersonService,
PersonUpdateDto,
} from '@app/domain';
import { Body, Controller, Get, Param, Post, Put, Query, StreamableFile } from '@nestjs/common';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { Authenticated, AuthUser } from '../app.guard';
import { UseValidation } from '../app.utils';
2023-05-17 13:07:17 -04:00
import { UUIDParamDto } from './dto/uuid-param.dto';
function asStreamableFile({ stream, type, length }: ImmichReadStream) {
return new StreamableFile(stream, { type, length });
}
@ApiTags('Person')
@Controller('person')
@Authenticated()
@UseValidation()
export class PersonController {
constructor(private service: PersonService) {}
@Get()
getAllPeople(@AuthUser() authUser: AuthUserDto, @Query() withHidden: PersonSearchDto): Promise<PeopleResponseDto> {
return this.service.getAll(authUser, withHidden);
2023-05-17 13:07:17 -04:00
}
@Get(':id')
getPerson(@AuthUser() authUser: AuthUserDto, @Param() { id }: UUIDParamDto): Promise<PersonResponseDto> {
2023-05-17 13:07:17 -04:00
return this.service.getById(authUser, id);
}
@Put(':id')
updatePerson(
@AuthUser() authUser: AuthUserDto,
2023-05-17 13:07:17 -04:00
@Param() { id }: UUIDParamDto,
@Body() dto: PersonUpdateDto,
): Promise<PersonResponseDto> {
return this.service.update(authUser, id, dto);
}
@Get(':id/thumbnail')
@ApiOkResponse({
content: {
'image/jpeg': { schema: { type: 'string', format: 'binary' } },
},
})
getPersonThumbnail(@AuthUser() authUser: AuthUserDto, @Param() { id }: UUIDParamDto) {
2023-05-17 13:07:17 -04:00
return this.service.getThumbnail(authUser, id).then(asStreamableFile);
}
@Get(':id/assets')
getPersonAssets(@AuthUser() authUser: AuthUserDto, @Param() { id }: UUIDParamDto): Promise<AssetResponseDto[]> {
2023-05-17 13:07:17 -04:00
return this.service.getAssets(authUser, id);
}
@Post(':id/merge')
mergePerson(
@AuthUser() authUser: AuthUserDto,
@Param() { id }: UUIDParamDto,
@Body() dto: MergePersonDto,
): Promise<BulkIdResponseDto[]> {
return this.service.mergePerson(authUser, id, dto);
}
2023-05-17 13:07:17 -04:00
}