Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server,web): hide faces #3262

Merged
merged 31 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cli/src/api/open-api/api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mobile/openapi/doc/PersonResponseDto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mobile/openapi/doc/PersonUpdateDto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions mobile/openapi/lib/model/person_response_dto.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions mobile/openapi/lib/model/person_update_dto.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions mobile/openapi/test/person_response_dto_test.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions mobile/openapi/test/person_update_dto_test.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion server/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5895,12 +5895,16 @@
},
"thumbnailPath": {
"type": "string"
},
"hidden": {
"type": "boolean"
}
},
"required": [
"id",
"name",
"thumbnailPath"
"thumbnailPath",
"hidden"
]
},
"PersonUpdateDto": {
Expand All @@ -5913,6 +5917,10 @@
"featureFaceAssetId": {
"type": "string",
"description": "Asset is used to get the feature face thumbnail."
},
"hidden": {
"type": "boolean",
"description": "Person visibility"
}
}
},
Expand Down
15 changes: 13 additions & 2 deletions server/src/domain/person/person.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AssetFaceEntity, PersonEntity } from '@app/infra/entities';
import { IsOptional, IsString } from 'class-validator';
import { ValidateUUID } from '../domain.util';
import { Transform } from 'class-transformer';
import { IsBoolean, IsOptional, IsString } from 'class-validator';
import { toBoolean, ValidateUUID } from '../domain.util';

export class PersonUpdateDto {
/**
Expand All @@ -16,6 +17,14 @@ export class PersonUpdateDto {
@IsOptional()
@IsString()
featureFaceAssetId?: string;

/**
* Person visibility
*/
@IsOptional()
@IsBoolean()
@Transform(toBoolean)
hidden?: boolean;
}

export class MergePersonDto {
Expand All @@ -27,13 +36,15 @@ export class PersonResponseDto {
id!: string;
name!: string;
thumbnailPath!: string;
hidden!: boolean;
}

export function mapPerson(person: PersonEntity): PersonResponseDto {
return {
id: person.id,
name: person.name,
thumbnailPath: person.thumbnailPath,
hidden: person.hidden,
};
}

Expand Down
1 change: 1 addition & 0 deletions server/src/domain/person/person.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const responseDto: PersonResponseDto = {
id: 'person-1',
name: 'Person 1',
thumbnailPath: '/path/to/thumbnail.jpg',
hidden: false,
};

describe(PersonService.name, () => {
Expand Down
8 changes: 8 additions & 0 deletions server/src/domain/person/person.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class PersonService {
const people = await this.repository.getAll(authUser.id, { minimumFaceCount: 1 });
const named = people.filter((person) => !!person.name);
const unnamed = people.filter((person) => !person.name);

return (
[...named, ...unnamed]
// with thumbnails
Expand Down Expand Up @@ -57,6 +58,13 @@ export class PersonService {
await this.jobRepository.queue({ name: JobName.SEARCH_INDEX_ASSET, data: { ids } });
}

if (dto.hidden !== undefined) {
person = await this.repository.update({ id, hidden: dto.hidden });
const assets = await this.repository.getAssets(authUser.id, id);
const ids = assets.map((asset) => asset.id);
await this.jobRepository.queue({ name: JobName.SEARCH_INDEX_ASSET, data: { ids } });
}

if (dto.featureFaceAssetId) {
const assetId = dto.featureFaceAssetId;
const face = await this.repository.getFaceById({ personId: id, assetId });
Expand Down
3 changes: 3 additions & 0 deletions server/src/infra/entities/person.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ export class PersonEntity {

@OneToMany(() => AssetFaceEntity, (assetFace) => assetFace.person)
faces!: AssetFaceEntity[];

@Column({ default: false })
hidden!: boolean;
}
14 changes: 14 additions & 0 deletions server/src/infra/migrations/1689281196844-AddHiddenFaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class Infra1689281196844 implements MigrationInterface {
name = 'Infra1689281196844'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "person" ADD "hidden" boolean NOT NULL DEFAULT false`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "person" DROP COLUMN "hidden"`);
}

}
28 changes: 28 additions & 0 deletions server/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,7 @@ export const personStub = {
name: '',
thumbnailPath: '/path/to/thumbnail.jpg',
faces: [],
hidden: false,
}),
withName: Object.freeze<PersonEntity>({
id: 'person-1',
Expand All @@ -1170,6 +1171,29 @@ export const personStub = {
name: 'Person 1',
thumbnailPath: '/path/to/thumbnail.jpg',
faces: [],
hidden: false,
}),
isHidden: Object.freeze<PersonEntity>({
id: 'person-1',
createdAt: new Date('2021-01-01'),
updatedAt: new Date('2021-01-01'),
ownerId: userEntityStub.admin.id,
owner: userEntityStub.admin,
name: 'Person 1',
thumbnailPath: '/path/to/thumbnail.jpg',
faces: [],
hidden: false,
}),
isnotHidden: Object.freeze<PersonEntity>({
martabal marked this conversation as resolved.
Show resolved Hide resolved
id: 'person-1',
createdAt: new Date('2021-01-01'),
updatedAt: new Date('2021-01-01'),
ownerId: userEntityStub.admin.id,
owner: userEntityStub.admin,
name: 'Person 1',
thumbnailPath: '/path/to/thumbnail.jpg',
faces: [],
hidden: true,
}),
noThumbnail: Object.freeze<PersonEntity>({
id: 'person-1',
Expand All @@ -1180,6 +1204,7 @@ export const personStub = {
name: '',
thumbnailPath: '',
faces: [],
hidden: false,
}),
newThumbnail: Object.freeze<PersonEntity>({
id: 'person-1',
Expand All @@ -1190,6 +1215,7 @@ export const personStub = {
name: '',
thumbnailPath: '/new/path/to/thumbnail.jpg',
faces: [],
hidden: false,
}),
primaryPerson: Object.freeze<PersonEntity>({
id: 'person-1',
Expand All @@ -1200,6 +1226,7 @@ export const personStub = {
name: 'Person 1',
thumbnailPath: '/path/to/thumbnail',
faces: [],
hidden: false,
}),
mergePerson: Object.freeze<PersonEntity>({
id: 'person-2',
Expand All @@ -1210,6 +1237,7 @@ export const personStub = {
name: 'Person 2',
thumbnailPath: '/path/to/thumbnail',
faces: [],
hidden: false,
}),
};

Expand Down
Loading
Loading