Skip to content

Commit

Permalink
addFaceInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
rikifrank committed Nov 7, 2023
1 parent e9ce968 commit 0f73ce8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server/src/domain/asset/response-dto/asset-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AssetEntity, AssetType } from '@app/infra/entities';
import { ApiProperty } from '@nestjs/swagger';
import { PersonResponseDto, mapFace } from '../../person/person.dto';
import { ExpandedPersonResponseDto, PersonResponseDto, mapExpandedPerson, mapFace } from '../../person/person.dto';
import { TagResponseDto, mapTag } from '../../tag';
import { UserResponseDto, mapUser } from '../../user/response-dto/user-response.dto';
import { ExifResponseDto, mapExif } from './exif-response.dto';
Expand Down Expand Up @@ -97,15 +97,15 @@ export function mapAsset(entity: AssetEntity, options: AssetMapOptions = {}): As
livePhotoVideoId: entity.livePhotoVideoId,
tags: entity.tags?.map(mapTag),
people: entity.faces
?.map(mapFace)
.filter((person): person is PersonResponseDto => person !== null && !person.isHidden)
?.map(mapExpandedPerson)
.filter((person): person is ExpandedPersonResponseDto => person !== null && !person.isHidden)
.reduce((people, person) => {
const existingPerson = people.find((p) => p.id === person.id);
if (!existingPerson) {
people.push(person);
}
return people;
}, [] as PersonResponseDto[]),
}, [] as ExpandedPersonResponseDto[]),
checksum: entity.checksum.toString('base64'),
stackParentId: entity.stackParentId,
stack: withStack ? entity.stack?.map((a) => mapAsset(a, { stripMetadata })) ?? undefined : undefined,
Expand Down
39 changes: 39 additions & 0 deletions server/src/domain/person/person.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ export class PersonResponseDto {
isHidden!: boolean;
}

export class ExpandedPersonResponseDto extends PersonResponseDto{
x1!: number;
x2!: number;
y1!: number;
y2!: number;
imageWidth!: number;
imageHeight!: number;
}

export class PersonStatisticsResponseDto {
@ApiProperty({ type: 'integer' })
assets!: number;
Expand Down Expand Up @@ -105,3 +114,33 @@ export function mapFace(face: AssetFaceEntity): PersonResponseDto | null {

return null;
}

export function mapExpandedPerson(face: AssetFaceEntity): ExpandedPersonResponseDto | null {
const {
boundingBoxX1: x1,
boundingBoxX2: x2,
boundingBoxY1: y1,
boundingBoxY2: y2,
imageWidth,
imageHeight,
} = face;

if (face.person) {
const personDTO = mapPerson(face.person);
return {
id: personDTO.id,
name: personDTO.name,
birthDate: personDTO.birthDate,
thumbnailPath: personDTO.thumbnailPath,
isHidden: personDTO.isHidden,
x1,
x2,
y1,
y2,
imageWidth,
imageHeight,
}
}

return null;
}

0 comments on commit 0f73ce8

Please sign in to comment.