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

190 lines
5.9 KiB
TypeScript
Raw Normal View History

import {
Body,
Controller,
Delete,
Get,
HttpCode,
HttpStatus,
Next,
Param,
Post,
Put,
Query,
Res,
} from '@nestjs/common';
2025-11-13 08:18:43 -05:00
import { ApiTags } from '@nestjs/swagger';
import { NextFunction, Response } from 'express';
2025-11-13 08:18:43 -05:00
import { Endpoint, HistoryBuilder } from 'src/decorators';
import { BulkIdResponseDto, BulkIdsDto } from 'src/dtos/asset-ids.response.dto';
import { AuthDto } from 'src/dtos/auth.dto';
2023-05-17 13:07:17 -04:00
import {
feat(web): re-assign person faces (2) (#4949) * feat: unassign person faces * multiple improvements * chore: regenerate api * feat: improve face interactions in photos * fix: tests * fix: tests * optimize * fix: wrong assignment on complex-multiple re-assignments * fix: thumbnails with large photos * fix: complex reassign * fix: don't send people with faces * fix: person thumbnail generation * chore: regenerate api * add tess * feat: face box even when zoomed * fix: change feature photo * feat: make the blue icon hoverable * chore: regenerate api * feat: use websocket * fix: loading spinner when clicking on the done button * fix: use the svelte way * fix: tests * simplify * fix: unused vars * fix: remove unused code * fix: add migration * chore: regenerate api * ci: add unit tests * chore: regenerate api * feat: if a new person is created for a face and the server takes more than 15 seconds to generate the person thumbnail, don't wait for it * reorganize * chore: regenerate api * feat: global edit * pr feedback * pr feedback * simplify * revert test * fix: face generation * fix: tests * fix: face generation * fix merge * feat: search names in unmerge face selector modal * fix: merge face selector * simplify feature photo generation * fix: change endpoint * pr feedback * chore: fix merge * chore: fix merge * fix: tests * fix: edit & hide buttons * fix: tests * feat: show if person is hidden * feat: rename face to person * feat: split in new panel * copy-paste-error * pr feedback * fix: feature photo * do not leak faces * fix: unmerge modal * fix: merge modal event * feat(server): remove duplicates * fix: title for image thumbnails * fix: disable side panel when there's no face until next PR --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2023-12-05 16:43:15 +01:00
AssetFaceUpdateDto,
MergePersonDto,
PeopleResponseDto,
PeopleUpdateDto,
PersonCreateDto,
2023-05-17 13:07:17 -04:00
PersonResponseDto,
PersonSearchDto,
PersonStatisticsResponseDto,
2023-05-17 13:07:17 -04:00
PersonUpdateDto,
} from 'src/dtos/person.dto';
2025-11-11 17:01:14 -05:00
import { ApiTag, Permission } from 'src/enum';
import { Auth, Authenticated, FileResponse } from 'src/middleware/auth.guard';
2025-01-23 08:31:30 -05:00
import { LoggingRepository } from 'src/repositories/logging.repository';
import { PersonService } from 'src/services/person.service';
2024-03-21 08:07:47 -05:00
import { sendFile } from 'src/utils/file';
import { UUIDParamDto } from 'src/validation';
2023-05-17 13:07:17 -04:00
2025-11-11 17:01:14 -05:00
@ApiTags(ApiTag.People)
@Controller('people')
2023-05-17 13:07:17 -04:00
export class PersonController {
2024-05-14 08:48:49 -04:00
constructor(
private service: PersonService,
2025-01-23 08:31:30 -05:00
private logger: LoggingRepository,
) {
this.logger.setContext(PersonController.name);
}
2023-05-17 13:07:17 -04:00
@Get()
2025-07-15 14:50:13 -04:00
@Authenticated({ permission: Permission.PersonRead })
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Get all people',
description: 'Retrieve a list of all people.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
getAllPeople(@Auth() auth: AuthDto, @Query() options: PersonSearchDto): Promise<PeopleResponseDto> {
return this.service.getAll(auth, options);
2023-05-17 13:07:17 -04:00
}
feat(web): re-assign person faces (2) (#4949) * feat: unassign person faces * multiple improvements * chore: regenerate api * feat: improve face interactions in photos * fix: tests * fix: tests * optimize * fix: wrong assignment on complex-multiple re-assignments * fix: thumbnails with large photos * fix: complex reassign * fix: don't send people with faces * fix: person thumbnail generation * chore: regenerate api * add tess * feat: face box even when zoomed * fix: change feature photo * feat: make the blue icon hoverable * chore: regenerate api * feat: use websocket * fix: loading spinner when clicking on the done button * fix: use the svelte way * fix: tests * simplify * fix: unused vars * fix: remove unused code * fix: add migration * chore: regenerate api * ci: add unit tests * chore: regenerate api * feat: if a new person is created for a face and the server takes more than 15 seconds to generate the person thumbnail, don't wait for it * reorganize * chore: regenerate api * feat: global edit * pr feedback * pr feedback * simplify * revert test * fix: face generation * fix: tests * fix: face generation * fix merge * feat: search names in unmerge face selector modal * fix: merge face selector * simplify feature photo generation * fix: change endpoint * pr feedback * chore: fix merge * chore: fix merge * fix: tests * fix: edit & hide buttons * fix: tests * feat: show if person is hidden * feat: rename face to person * feat: split in new panel * copy-paste-error * pr feedback * fix: feature photo * do not leak faces * fix: unmerge modal * fix: merge modal event * feat(server): remove duplicates * fix: title for image thumbnails * fix: disable side panel when there's no face until next PR --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2023-12-05 16:43:15 +01:00
@Post()
2025-07-15 14:50:13 -04:00
@Authenticated({ permission: Permission.PersonCreate })
2025-11-13 08:18:43 -05:00
@Endpoint({
2025-11-11 17:01:14 -05:00
summary: 'Create a person',
description: 'Create a new person that can have multiple faces assigned to them.',
2025-11-13 08:18:43 -05:00
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
2025-11-11 17:01:14 -05:00
})
createPerson(@Auth() auth: AuthDto, @Body() dto: PersonCreateDto): Promise<PersonResponseDto> {
return this.service.create(auth, dto);
feat(web): re-assign person faces (2) (#4949) * feat: unassign person faces * multiple improvements * chore: regenerate api * feat: improve face interactions in photos * fix: tests * fix: tests * optimize * fix: wrong assignment on complex-multiple re-assignments * fix: thumbnails with large photos * fix: complex reassign * fix: don't send people with faces * fix: person thumbnail generation * chore: regenerate api * add tess * feat: face box even when zoomed * fix: change feature photo * feat: make the blue icon hoverable * chore: regenerate api * feat: use websocket * fix: loading spinner when clicking on the done button * fix: use the svelte way * fix: tests * simplify * fix: unused vars * fix: remove unused code * fix: add migration * chore: regenerate api * ci: add unit tests * chore: regenerate api * feat: if a new person is created for a face and the server takes more than 15 seconds to generate the person thumbnail, don't wait for it * reorganize * chore: regenerate api * feat: global edit * pr feedback * pr feedback * simplify * revert test * fix: face generation * fix: tests * fix: face generation * fix merge * feat: search names in unmerge face selector modal * fix: merge face selector * simplify feature photo generation * fix: change endpoint * pr feedback * chore: fix merge * chore: fix merge * fix: tests * fix: edit & hide buttons * fix: tests * feat: show if person is hidden * feat: rename face to person * feat: split in new panel * copy-paste-error * pr feedback * fix: feature photo * do not leak faces * fix: unmerge modal * fix: merge modal event * feat(server): remove duplicates * fix: title for image thumbnails * fix: disable side panel when there's no face until next PR --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2023-12-05 16:43:15 +01:00
}
@Put()
2025-07-15 14:50:13 -04:00
@Authenticated({ permission: Permission.PersonUpdate })
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Update people',
description: 'Bulk update multiple people at once.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
updatePeople(@Auth() auth: AuthDto, @Body() dto: PeopleUpdateDto): Promise<BulkIdResponseDto[]> {
return this.service.updateAll(auth, dto);
}
@Delete()
2025-07-15 14:50:13 -04:00
@Authenticated({ permission: Permission.PersonDelete })
@HttpCode(HttpStatus.NO_CONTENT)
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Delete people',
description: 'Bulk delete a list of people at once.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
deletePeople(@Auth() auth: AuthDto, @Body() dto: BulkIdsDto): Promise<void> {
return this.service.deleteAll(auth, dto);
}
2023-05-17 13:07:17 -04:00
@Get(':id')
2025-07-15 14:50:13 -04:00
@Authenticated({ permission: Permission.PersonRead })
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Get a person',
description: 'Retrieve a person by id.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
getPerson(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<PersonResponseDto> {
return this.service.getById(auth, id);
2023-05-17 13:07:17 -04:00
}
@Put(':id')
2025-07-15 14:50:13 -04:00
@Authenticated({ permission: Permission.PersonUpdate })
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Update person',
description: 'Update an individual person.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
2023-05-17 13:07:17 -04:00
updatePerson(
@Auth() auth: AuthDto,
2023-05-17 13:07:17 -04:00
@Param() { id }: UUIDParamDto,
@Body() dto: PersonUpdateDto,
): Promise<PersonResponseDto> {
return this.service.update(auth, id, dto);
2023-05-17 13:07:17 -04:00
}
@Delete(':id')
2025-07-15 14:50:13 -04:00
@Authenticated({ permission: Permission.PersonDelete })
@HttpCode(HttpStatus.NO_CONTENT)
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Delete person',
description: 'Delete an individual person.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
deletePerson(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<void> {
return this.service.delete(auth, id);
}
@Get(':id/statistics')
2025-07-15 14:50:13 -04:00
@Authenticated({ permission: Permission.PersonStatistics })
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Get person statistics',
description: 'Retrieve statistics about a specific person.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
getPersonStatistics(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<PersonStatisticsResponseDto> {
return this.service.getStatistics(auth, id);
}
2023-05-17 13:07:17 -04:00
@Get(':id/thumbnail')
@FileResponse()
2025-07-15 14:50:13 -04:00
@Authenticated({ permission: Permission.PersonRead })
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Get person thumbnail',
description: 'Retrieve the thumbnail file for a person.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
async getPersonThumbnail(
@Res() res: Response,
@Next() next: NextFunction,
@Auth() auth: AuthDto,
@Param() { id }: UUIDParamDto,
) {
2024-05-14 08:48:49 -04:00
await sendFile(res, next, () => this.service.getThumbnail(auth, id), this.logger);
2023-05-17 13:07:17 -04:00
}
@Put(':id/reassign')
2025-07-15 14:50:13 -04:00
@Authenticated({ permission: Permission.PersonReassign })
2025-11-13 08:18:43 -05:00
@Endpoint({
summary: 'Reassign faces',
description: 'Bulk reassign a list of faces to a different person.',
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
})
reassignFaces(
@Auth() auth: AuthDto,
@Param() { id }: UUIDParamDto,
@Body() dto: AssetFaceUpdateDto,
): Promise<PersonResponseDto[]> {
return this.service.reassignFaces(auth, id, dto);
}
@Post(':id/merge')
2025-07-15 14:50:13 -04:00
@Authenticated({ permission: Permission.PersonMerge })
@HttpCode(HttpStatus.OK)
2025-11-13 08:18:43 -05:00
@Endpoint({
2025-11-11 17:01:14 -05:00
summary: 'Merge people',
description: 'Merge a list of people into the person specified in the path parameter.',
2025-11-13 08:18:43 -05:00
history: new HistoryBuilder().added('v1').beta('v1').stable('v2'),
2025-11-11 17:01:14 -05:00
})
mergePerson(
@Auth() auth: AuthDto,
@Param() { id }: UUIDParamDto,
@Body() dto: MergePersonDto,
): Promise<BulkIdResponseDto[]> {
return this.service.mergePerson(auth, id, dto);
}
2023-05-17 13:07:17 -04:00
}