feat: asset face sync (#20048)

* chore: remove thumbnailPath from person sync dto

* feat: asset face sync
This commit is contained in:
Zack Pollard 2025-07-22 02:31:45 +01:00 committed by GitHub
parent 826eaedae6
commit df318ac641
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 699 additions and 20 deletions

View File

@ -523,7 +523,6 @@ class SyncStreamRepository extends DriftDatabaseRepository {
ownerId: Value(person.ownerId), ownerId: Value(person.ownerId),
name: Value(person.name), name: Value(person.name),
faceAssetId: Value(person.faceAssetId), faceAssetId: Value(person.faceAssetId),
thumbnailPath: Value(person.thumbnailPath),
isFavorite: Value(person.isFavorite), isFavorite: Value(person.isFavorite),
isHidden: Value(person.isHidden), isHidden: Value(person.isHidden),
color: Value(person.color), color: Value(person.color),

View File

@ -475,6 +475,8 @@ Class | Method | HTTP request | Description
- [SyncAlbumV1](doc//SyncAlbumV1.md) - [SyncAlbumV1](doc//SyncAlbumV1.md)
- [SyncAssetDeleteV1](doc//SyncAssetDeleteV1.md) - [SyncAssetDeleteV1](doc//SyncAssetDeleteV1.md)
- [SyncAssetExifV1](doc//SyncAssetExifV1.md) - [SyncAssetExifV1](doc//SyncAssetExifV1.md)
- [SyncAssetFaceDeleteV1](doc//SyncAssetFaceDeleteV1.md)
- [SyncAssetFaceV1](doc//SyncAssetFaceV1.md)
- [SyncAssetV1](doc//SyncAssetV1.md) - [SyncAssetV1](doc//SyncAssetV1.md)
- [SyncEntityType](doc//SyncEntityType.md) - [SyncEntityType](doc//SyncEntityType.md)
- [SyncMemoryAssetDeleteV1](doc//SyncMemoryAssetDeleteV1.md) - [SyncMemoryAssetDeleteV1](doc//SyncMemoryAssetDeleteV1.md)

View File

@ -257,6 +257,8 @@ part 'model/sync_album_user_v1.dart';
part 'model/sync_album_v1.dart'; part 'model/sync_album_v1.dart';
part 'model/sync_asset_delete_v1.dart'; part 'model/sync_asset_delete_v1.dart';
part 'model/sync_asset_exif_v1.dart'; part 'model/sync_asset_exif_v1.dart';
part 'model/sync_asset_face_delete_v1.dart';
part 'model/sync_asset_face_v1.dart';
part 'model/sync_asset_v1.dart'; part 'model/sync_asset_v1.dart';
part 'model/sync_entity_type.dart'; part 'model/sync_entity_type.dart';
part 'model/sync_memory_asset_delete_v1.dart'; part 'model/sync_memory_asset_delete_v1.dart';

View File

@ -570,6 +570,10 @@ class ApiClient {
return SyncAssetDeleteV1.fromJson(value); return SyncAssetDeleteV1.fromJson(value);
case 'SyncAssetExifV1': case 'SyncAssetExifV1':
return SyncAssetExifV1.fromJson(value); return SyncAssetExifV1.fromJson(value);
case 'SyncAssetFaceDeleteV1':
return SyncAssetFaceDeleteV1.fromJson(value);
case 'SyncAssetFaceV1':
return SyncAssetFaceV1.fromJson(value);
case 'SyncAssetV1': case 'SyncAssetV1':
return SyncAssetV1.fromJson(value); return SyncAssetV1.fromJson(value);
case 'SyncEntityType': case 'SyncEntityType':

View File

@ -0,0 +1,99 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.18
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class SyncAssetFaceDeleteV1 {
/// Returns a new [SyncAssetFaceDeleteV1] instance.
SyncAssetFaceDeleteV1({
required this.assetFaceId,
});
String assetFaceId;
@override
bool operator ==(Object other) => identical(this, other) || other is SyncAssetFaceDeleteV1 &&
other.assetFaceId == assetFaceId;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(assetFaceId.hashCode);
@override
String toString() => 'SyncAssetFaceDeleteV1[assetFaceId=$assetFaceId]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'assetFaceId'] = this.assetFaceId;
return json;
}
/// Returns a new [SyncAssetFaceDeleteV1] instance and imports its values from
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static SyncAssetFaceDeleteV1? fromJson(dynamic value) {
upgradeDto(value, "SyncAssetFaceDeleteV1");
if (value is Map) {
final json = value.cast<String, dynamic>();
return SyncAssetFaceDeleteV1(
assetFaceId: mapValueOfType<String>(json, r'assetFaceId')!,
);
}
return null;
}
static List<SyncAssetFaceDeleteV1> listFromJson(dynamic json, {bool growable = false,}) {
final result = <SyncAssetFaceDeleteV1>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = SyncAssetFaceDeleteV1.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
static Map<String, SyncAssetFaceDeleteV1> mapFromJson(dynamic json) {
final map = <String, SyncAssetFaceDeleteV1>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = SyncAssetFaceDeleteV1.fromJson(entry.value);
if (value != null) {
map[entry.key] = value;
}
}
}
return map;
}
// maps a json object with a list of SyncAssetFaceDeleteV1-objects as value to a dart map
static Map<String, List<SyncAssetFaceDeleteV1>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<SyncAssetFaceDeleteV1>>{};
if (json is Map && json.isNotEmpty) {
// ignore: parameter_assignments
json = json.cast<String, dynamic>();
for (final entry in json.entries) {
map[entry.key] = SyncAssetFaceDeleteV1.listFromJson(entry.value, growable: growable,);
}
}
return map;
}
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'assetFaceId',
};
}

View File

@ -0,0 +1,175 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.18
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class SyncAssetFaceV1 {
/// Returns a new [SyncAssetFaceV1] instance.
SyncAssetFaceV1({
required this.assetId,
required this.boundingBoxX1,
required this.boundingBoxX2,
required this.boundingBoxY1,
required this.boundingBoxY2,
required this.id,
required this.imageHeight,
required this.imageWidth,
required this.personId,
required this.sourceType,
});
String assetId;
num boundingBoxX1;
num boundingBoxX2;
num boundingBoxY1;
num boundingBoxY2;
String id;
num imageHeight;
num imageWidth;
String? personId;
String sourceType;
@override
bool operator ==(Object other) => identical(this, other) || other is SyncAssetFaceV1 &&
other.assetId == assetId &&
other.boundingBoxX1 == boundingBoxX1 &&
other.boundingBoxX2 == boundingBoxX2 &&
other.boundingBoxY1 == boundingBoxY1 &&
other.boundingBoxY2 == boundingBoxY2 &&
other.id == id &&
other.imageHeight == imageHeight &&
other.imageWidth == imageWidth &&
other.personId == personId &&
other.sourceType == sourceType;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(assetId.hashCode) +
(boundingBoxX1.hashCode) +
(boundingBoxX2.hashCode) +
(boundingBoxY1.hashCode) +
(boundingBoxY2.hashCode) +
(id.hashCode) +
(imageHeight.hashCode) +
(imageWidth.hashCode) +
(personId == null ? 0 : personId!.hashCode) +
(sourceType.hashCode);
@override
String toString() => 'SyncAssetFaceV1[assetId=$assetId, boundingBoxX1=$boundingBoxX1, boundingBoxX2=$boundingBoxX2, boundingBoxY1=$boundingBoxY1, boundingBoxY2=$boundingBoxY2, id=$id, imageHeight=$imageHeight, imageWidth=$imageWidth, personId=$personId, sourceType=$sourceType]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'assetId'] = this.assetId;
json[r'boundingBoxX1'] = this.boundingBoxX1;
json[r'boundingBoxX2'] = this.boundingBoxX2;
json[r'boundingBoxY1'] = this.boundingBoxY1;
json[r'boundingBoxY2'] = this.boundingBoxY2;
json[r'id'] = this.id;
json[r'imageHeight'] = this.imageHeight;
json[r'imageWidth'] = this.imageWidth;
if (this.personId != null) {
json[r'personId'] = this.personId;
} else {
// json[r'personId'] = null;
}
json[r'sourceType'] = this.sourceType;
return json;
}
/// Returns a new [SyncAssetFaceV1] instance and imports its values from
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static SyncAssetFaceV1? fromJson(dynamic value) {
upgradeDto(value, "SyncAssetFaceV1");
if (value is Map) {
final json = value.cast<String, dynamic>();
return SyncAssetFaceV1(
assetId: mapValueOfType<String>(json, r'assetId')!,
boundingBoxX1: num.parse('${json[r'boundingBoxX1']}'),
boundingBoxX2: num.parse('${json[r'boundingBoxX2']}'),
boundingBoxY1: num.parse('${json[r'boundingBoxY1']}'),
boundingBoxY2: num.parse('${json[r'boundingBoxY2']}'),
id: mapValueOfType<String>(json, r'id')!,
imageHeight: num.parse('${json[r'imageHeight']}'),
imageWidth: num.parse('${json[r'imageWidth']}'),
personId: mapValueOfType<String>(json, r'personId'),
sourceType: mapValueOfType<String>(json, r'sourceType')!,
);
}
return null;
}
static List<SyncAssetFaceV1> listFromJson(dynamic json, {bool growable = false,}) {
final result = <SyncAssetFaceV1>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = SyncAssetFaceV1.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
static Map<String, SyncAssetFaceV1> mapFromJson(dynamic json) {
final map = <String, SyncAssetFaceV1>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = SyncAssetFaceV1.fromJson(entry.value);
if (value != null) {
map[entry.key] = value;
}
}
}
return map;
}
// maps a json object with a list of SyncAssetFaceV1-objects as value to a dart map
static Map<String, List<SyncAssetFaceV1>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<SyncAssetFaceV1>>{};
if (json is Map && json.isNotEmpty) {
// ignore: parameter_assignments
json = json.cast<String, dynamic>();
for (final entry in json.entries) {
map[entry.key] = SyncAssetFaceV1.listFromJson(entry.value, growable: growable,);
}
}
return map;
}
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'assetId',
'boundingBoxX1',
'boundingBoxX2',
'boundingBoxY1',
'boundingBoxY2',
'id',
'imageHeight',
'imageWidth',
'personId',
'sourceType',
};
}

View File

@ -58,6 +58,8 @@ class SyncEntityType {
static const stackDeleteV1 = SyncEntityType._(r'StackDeleteV1'); static const stackDeleteV1 = SyncEntityType._(r'StackDeleteV1');
static const personV1 = SyncEntityType._(r'PersonV1'); static const personV1 = SyncEntityType._(r'PersonV1');
static const personDeleteV1 = SyncEntityType._(r'PersonDeleteV1'); static const personDeleteV1 = SyncEntityType._(r'PersonDeleteV1');
static const assetFaceV1 = SyncEntityType._(r'AssetFaceV1');
static const assetFaceDeleteV1 = SyncEntityType._(r'AssetFaceDeleteV1');
static const userMetadataV1 = SyncEntityType._(r'UserMetadataV1'); static const userMetadataV1 = SyncEntityType._(r'UserMetadataV1');
static const userMetadataDeleteV1 = SyncEntityType._(r'UserMetadataDeleteV1'); static const userMetadataDeleteV1 = SyncEntityType._(r'UserMetadataDeleteV1');
static const syncAckV1 = SyncEntityType._(r'SyncAckV1'); static const syncAckV1 = SyncEntityType._(r'SyncAckV1');
@ -100,6 +102,8 @@ class SyncEntityType {
stackDeleteV1, stackDeleteV1,
personV1, personV1,
personDeleteV1, personDeleteV1,
assetFaceV1,
assetFaceDeleteV1,
userMetadataV1, userMetadataV1,
userMetadataDeleteV1, userMetadataDeleteV1,
syncAckV1, syncAckV1,
@ -177,6 +181,8 @@ class SyncEntityTypeTypeTransformer {
case r'StackDeleteV1': return SyncEntityType.stackDeleteV1; case r'StackDeleteV1': return SyncEntityType.stackDeleteV1;
case r'PersonV1': return SyncEntityType.personV1; case r'PersonV1': return SyncEntityType.personV1;
case r'PersonDeleteV1': return SyncEntityType.personDeleteV1; case r'PersonDeleteV1': return SyncEntityType.personDeleteV1;
case r'AssetFaceV1': return SyncEntityType.assetFaceV1;
case r'AssetFaceDeleteV1': return SyncEntityType.assetFaceDeleteV1;
case r'UserMetadataV1': return SyncEntityType.userMetadataV1; case r'UserMetadataV1': return SyncEntityType.userMetadataV1;
case r'UserMetadataDeleteV1': return SyncEntityType.userMetadataDeleteV1; case r'UserMetadataDeleteV1': return SyncEntityType.userMetadataDeleteV1;
case r'SyncAckV1': return SyncEntityType.syncAckV1; case r'SyncAckV1': return SyncEntityType.syncAckV1;

View File

@ -22,7 +22,6 @@ class SyncPersonV1 {
required this.isHidden, required this.isHidden,
required this.name, required this.name,
required this.ownerId, required this.ownerId,
required this.thumbnailPath,
required this.updatedAt, required this.updatedAt,
}); });
@ -44,8 +43,6 @@ class SyncPersonV1 {
String ownerId; String ownerId;
String thumbnailPath;
DateTime updatedAt; DateTime updatedAt;
@override @override
@ -59,7 +56,6 @@ class SyncPersonV1 {
other.isHidden == isHidden && other.isHidden == isHidden &&
other.name == name && other.name == name &&
other.ownerId == ownerId && other.ownerId == ownerId &&
other.thumbnailPath == thumbnailPath &&
other.updatedAt == updatedAt; other.updatedAt == updatedAt;
@override @override
@ -74,11 +70,10 @@ class SyncPersonV1 {
(isHidden.hashCode) + (isHidden.hashCode) +
(name.hashCode) + (name.hashCode) +
(ownerId.hashCode) + (ownerId.hashCode) +
(thumbnailPath.hashCode) +
(updatedAt.hashCode); (updatedAt.hashCode);
@override @override
String toString() => 'SyncPersonV1[birthDate=$birthDate, color=$color, createdAt=$createdAt, faceAssetId=$faceAssetId, id=$id, isFavorite=$isFavorite, isHidden=$isHidden, name=$name, ownerId=$ownerId, thumbnailPath=$thumbnailPath, updatedAt=$updatedAt]'; String toString() => 'SyncPersonV1[birthDate=$birthDate, color=$color, createdAt=$createdAt, faceAssetId=$faceAssetId, id=$id, isFavorite=$isFavorite, isHidden=$isHidden, name=$name, ownerId=$ownerId, updatedAt=$updatedAt]';
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final json = <String, dynamic>{}; final json = <String, dynamic>{};
@ -103,7 +98,6 @@ class SyncPersonV1 {
json[r'isHidden'] = this.isHidden; json[r'isHidden'] = this.isHidden;
json[r'name'] = this.name; json[r'name'] = this.name;
json[r'ownerId'] = this.ownerId; json[r'ownerId'] = this.ownerId;
json[r'thumbnailPath'] = this.thumbnailPath;
json[r'updatedAt'] = this.updatedAt.toUtc().toIso8601String(); json[r'updatedAt'] = this.updatedAt.toUtc().toIso8601String();
return json; return json;
} }
@ -126,7 +120,6 @@ class SyncPersonV1 {
isHidden: mapValueOfType<bool>(json, r'isHidden')!, isHidden: mapValueOfType<bool>(json, r'isHidden')!,
name: mapValueOfType<String>(json, r'name')!, name: mapValueOfType<String>(json, r'name')!,
ownerId: mapValueOfType<String>(json, r'ownerId')!, ownerId: mapValueOfType<String>(json, r'ownerId')!,
thumbnailPath: mapValueOfType<String>(json, r'thumbnailPath')!,
updatedAt: mapDateTime(json, r'updatedAt', r'')!, updatedAt: mapDateTime(json, r'updatedAt', r'')!,
); );
} }
@ -184,7 +177,6 @@ class SyncPersonV1 {
'isHidden', 'isHidden',
'name', 'name',
'ownerId', 'ownerId',
'thumbnailPath',
'updatedAt', 'updatedAt',
}; };
} }

View File

@ -39,6 +39,7 @@ class SyncRequestType {
static const stacksV1 = SyncRequestType._(r'StacksV1'); static const stacksV1 = SyncRequestType._(r'StacksV1');
static const usersV1 = SyncRequestType._(r'UsersV1'); static const usersV1 = SyncRequestType._(r'UsersV1');
static const peopleV1 = SyncRequestType._(r'PeopleV1'); static const peopleV1 = SyncRequestType._(r'PeopleV1');
static const assetFacesV1 = SyncRequestType._(r'AssetFacesV1');
static const userMetadataV1 = SyncRequestType._(r'UserMetadataV1'); static const userMetadataV1 = SyncRequestType._(r'UserMetadataV1');
/// List of all possible values in this [enum][SyncRequestType]. /// List of all possible values in this [enum][SyncRequestType].
@ -59,6 +60,7 @@ class SyncRequestType {
stacksV1, stacksV1,
usersV1, usersV1,
peopleV1, peopleV1,
assetFacesV1,
userMetadataV1, userMetadataV1,
]; ];
@ -114,6 +116,7 @@ class SyncRequestTypeTypeTransformer {
case r'StacksV1': return SyncRequestType.stacksV1; case r'StacksV1': return SyncRequestType.stacksV1;
case r'UsersV1': return SyncRequestType.usersV1; case r'UsersV1': return SyncRequestType.usersV1;
case r'PeopleV1': return SyncRequestType.peopleV1; case r'PeopleV1': return SyncRequestType.peopleV1;
case r'AssetFacesV1': return SyncRequestType.assetFacesV1;
case r'UserMetadataV1': return SyncRequestType.userMetadataV1; case r'UserMetadataV1': return SyncRequestType.userMetadataV1;
default: default:
if (!allowNull) { if (!allowNull) {

View File

@ -13788,6 +13788,65 @@
], ],
"type": "object" "type": "object"
}, },
"SyncAssetFaceDeleteV1": {
"properties": {
"assetFaceId": {
"type": "string"
}
},
"required": [
"assetFaceId"
],
"type": "object"
},
"SyncAssetFaceV1": {
"properties": {
"assetId": {
"type": "string"
},
"boundingBoxX1": {
"type": "number"
},
"boundingBoxX2": {
"type": "number"
},
"boundingBoxY1": {
"type": "number"
},
"boundingBoxY2": {
"type": "number"
},
"id": {
"type": "string"
},
"imageHeight": {
"type": "number"
},
"imageWidth": {
"type": "number"
},
"personId": {
"nullable": true,
"type": "string"
},
"sourceType": {
"type": "string"
}
},
"required": [
"assetId",
"boundingBoxX1",
"boundingBoxX2",
"boundingBoxY1",
"boundingBoxY2",
"id",
"imageHeight",
"imageWidth",
"personId",
"sourceType"
],
"type": "object"
},
"SyncAssetV1": { "SyncAssetV1": {
"properties": { "properties": {
"checksum": { "checksum": {
@ -13912,6 +13971,8 @@
"StackDeleteV1", "StackDeleteV1",
"PersonV1", "PersonV1",
"PersonDeleteV1", "PersonDeleteV1",
"AssetFaceV1",
"AssetFaceDeleteV1",
"UserMetadataV1", "UserMetadataV1",
"UserMetadataDeleteV1", "UserMetadataDeleteV1",
"SyncAckV1", "SyncAckV1",
@ -14109,9 +14170,6 @@
"ownerId": { "ownerId": {
"type": "string" "type": "string"
}, },
"thumbnailPath": {
"type": "string"
},
"updatedAt": { "updatedAt": {
"format": "date-time", "format": "date-time",
"type": "string" "type": "string"
@ -14127,7 +14185,6 @@
"isHidden", "isHidden",
"name", "name",
"ownerId", "ownerId",
"thumbnailPath",
"updatedAt" "updatedAt"
], ],
"type": "object" "type": "object"
@ -14150,6 +14207,7 @@
"StacksV1", "StacksV1",
"UsersV1", "UsersV1",
"PeopleV1", "PeopleV1",
"AssetFacesV1",
"UserMetadataV1" "UserMetadataV1"
], ],
"type": "string" "type": "string"

View File

@ -4125,6 +4125,8 @@ export enum SyncEntityType {
StackDeleteV1 = "StackDeleteV1", StackDeleteV1 = "StackDeleteV1",
PersonV1 = "PersonV1", PersonV1 = "PersonV1",
PersonDeleteV1 = "PersonDeleteV1", PersonDeleteV1 = "PersonDeleteV1",
AssetFaceV1 = "AssetFaceV1",
AssetFaceDeleteV1 = "AssetFaceDeleteV1",
UserMetadataV1 = "UserMetadataV1", UserMetadataV1 = "UserMetadataV1",
UserMetadataDeleteV1 = "UserMetadataDeleteV1", UserMetadataDeleteV1 = "UserMetadataDeleteV1",
SyncAckV1 = "SyncAckV1", SyncAckV1 = "SyncAckV1",
@ -4147,6 +4149,7 @@ export enum SyncRequestType {
StacksV1 = "StacksV1", StacksV1 = "StacksV1",
UsersV1 = "UsersV1", UsersV1 = "UsersV1",
PeopleV1 = "PeopleV1", PeopleV1 = "PeopleV1",
AssetFacesV1 = "AssetFacesV1",
UserMetadataV1 = "UserMetadataV1" UserMetadataV1 = "UserMetadataV1"
} }
export enum TranscodeHWAccel { export enum TranscodeHWAccel {

View File

@ -272,6 +272,8 @@ export type AssetFace = {
personId: string | null; personId: string | null;
sourceType: SourceType; sourceType: SourceType;
person?: Person | null; person?: Person | null;
updatedAt: Date;
updateId: string;
}; };
const userColumns = ['id', 'name', 'email', 'avatarColor', 'profileImagePath', 'profileChangedAt'] as const; const userColumns = ['id', 'name', 'email', 'avatarColor', 'profileImagePath', 'profileChangedAt'] as const;

View File

@ -245,7 +245,6 @@ export class SyncPersonV1 {
ownerId!: string; ownerId!: string;
name!: string; name!: string;
birthDate!: Date | null; birthDate!: Date | null;
thumbnailPath!: string;
isHidden!: boolean; isHidden!: boolean;
isFavorite!: boolean; isFavorite!: boolean;
color!: string | null; color!: string | null;
@ -257,6 +256,25 @@ export class SyncPersonDeleteV1 {
personId!: string; personId!: string;
} }
@ExtraModel()
export class SyncAssetFaceV1 {
id!: string;
assetId!: string;
personId!: string | null;
imageWidth!: number;
imageHeight!: number;
boundingBoxX1!: number;
boundingBoxY1!: number;
boundingBoxX2!: number;
boundingBoxY2!: number;
sourceType!: string;
}
@ExtraModel()
export class SyncAssetFaceDeleteV1 {
assetFaceId!: string;
}
@ExtraModel() @ExtraModel()
export class SyncUserMetadataV1 { export class SyncUserMetadataV1 {
userId!: string; userId!: string;
@ -312,6 +330,8 @@ export type SyncItem = {
[SyncEntityType.PartnerStackV1]: SyncStackV1; [SyncEntityType.PartnerStackV1]: SyncStackV1;
[SyncEntityType.PersonV1]: SyncPersonV1; [SyncEntityType.PersonV1]: SyncPersonV1;
[SyncEntityType.PersonDeleteV1]: SyncPersonDeleteV1; [SyncEntityType.PersonDeleteV1]: SyncPersonDeleteV1;
[SyncEntityType.AssetFaceV1]: SyncAssetFaceV1;
[SyncEntityType.AssetFaceDeleteV1]: SyncAssetFaceDeleteV1;
[SyncEntityType.UserMetadataV1]: SyncUserMetadataV1; [SyncEntityType.UserMetadataV1]: SyncUserMetadataV1;
[SyncEntityType.UserMetadataDeleteV1]: SyncUserMetadataDeleteV1; [SyncEntityType.UserMetadataDeleteV1]: SyncUserMetadataDeleteV1;
[SyncEntityType.SyncAckV1]: SyncAckV1; [SyncEntityType.SyncAckV1]: SyncAckV1;

View File

@ -568,6 +568,7 @@ export enum SyncRequestType {
StacksV1 = 'StacksV1', StacksV1 = 'StacksV1',
UsersV1 = 'UsersV1', UsersV1 = 'UsersV1',
PeopleV1 = 'PeopleV1', PeopleV1 = 'PeopleV1',
AssetFacesV1 = 'AssetFacesV1',
UserMetadataV1 = 'UserMetadataV1', UserMetadataV1 = 'UserMetadataV1',
} }
@ -619,6 +620,9 @@ export enum SyncEntityType {
PersonV1 = 'PersonV1', PersonV1 = 'PersonV1',
PersonDeleteV1 = 'PersonDeleteV1', PersonDeleteV1 = 'PersonDeleteV1',
AssetFaceV1 = 'AssetFaceV1',
AssetFaceDeleteV1 = 'AssetFaceDeleteV1',
UserMetadataV1 = 'UserMetadataV1', UserMetadataV1 = 'UserMetadataV1',
UserMetadataDeleteV1 = 'UserMetadataDeleteV1', UserMetadataDeleteV1 = 'UserMetadataDeleteV1',

View File

@ -409,6 +409,41 @@ where
order by order by
"updateId" asc "updateId" asc
-- SyncRepository.assetFace.getDeletes
select
"asset_face_audit"."id",
"assetFaceId"
from
"asset_face_audit"
left join "asset" on "asset"."id" = "asset_face_audit"."assetId"
where
"asset"."ownerId" = $1
and "asset_face_audit"."deletedAt" < now() - interval '1 millisecond'
order by
"asset_face_audit"."id" asc
-- SyncRepository.assetFace.getUpserts
select
"asset_face"."id",
"assetId",
"personId",
"imageWidth",
"imageHeight",
"boundingBoxX1",
"boundingBoxY1",
"boundingBoxX2",
"boundingBoxY2",
"sourceType",
"asset_face"."updateId"
from
"asset_face"
left join "asset" on "asset"."id" = "asset_face"."assetId"
where
"asset_face"."updatedAt" < now() - interval '1 millisecond'
and "asset"."ownerId" = $1
order by
"asset_face"."updateId" asc
-- SyncRepository.memory.getDeletes -- SyncRepository.memory.getDeletes
select select
"id", "id",
@ -779,7 +814,6 @@ select
"ownerId", "ownerId",
"name", "name",
"birthDate", "birthDate",
"thumbnailPath",
"isHidden", "isHidden",
"isFavorite", "isFavorite",
"color", "color",

View File

@ -17,7 +17,8 @@ type AuditTables =
| 'memory_asset_audit' | 'memory_asset_audit'
| 'stack_audit' | 'stack_audit'
| 'person_audit' | 'person_audit'
| 'user_metadata_audit'; | 'user_metadata_audit'
| 'asset_face_audit';
type UpsertTables = type UpsertTables =
| 'user' | 'user'
| 'partner' | 'partner'
@ -29,7 +30,8 @@ type UpsertTables =
| 'memory_asset' | 'memory_asset'
| 'stack' | 'stack'
| 'person' | 'person'
| 'user_metadata'; | 'user_metadata'
| 'asset_face';
@Injectable() @Injectable()
export class SyncRepository { export class SyncRepository {
@ -40,6 +42,7 @@ export class SyncRepository {
albumUser: AlbumUserSync; albumUser: AlbumUserSync;
asset: AssetSync; asset: AssetSync;
assetExif: AssetExifSync; assetExif: AssetExifSync;
assetFace: AssetFaceSync;
memory: MemorySync; memory: MemorySync;
memoryToAsset: MemoryToAssetSync; memoryToAsset: MemoryToAssetSync;
partner: PartnerSync; partner: PartnerSync;
@ -59,6 +62,7 @@ export class SyncRepository {
this.albumUser = new AlbumUserSync(this.db); this.albumUser = new AlbumUserSync(this.db);
this.asset = new AssetSync(this.db); this.asset = new AssetSync(this.db);
this.assetExif = new AssetExifSync(this.db); this.assetExif = new AssetExifSync(this.db);
this.assetFace = new AssetFaceSync(this.db);
this.memory = new MemorySync(this.db); this.memory = new MemorySync(this.db);
this.memoryToAsset = new MemoryToAssetSync(this.db); this.memoryToAsset = new MemoryToAssetSync(this.db);
this.partner = new PartnerSync(this.db); this.partner = new PartnerSync(this.db);
@ -385,7 +389,6 @@ class PersonSync extends BaseSync {
'ownerId', 'ownerId',
'name', 'name',
'birthDate', 'birthDate',
'thumbnailPath',
'isHidden', 'isHidden',
'isFavorite', 'isFavorite',
'color', 'color',
@ -398,6 +401,46 @@ class PersonSync extends BaseSync {
} }
} }
class AssetFaceSync extends BaseSync {
@GenerateSql({ params: [DummyValue.UUID], stream: true })
getDeletes(userId: string, ack?: SyncAck) {
return this.db
.selectFrom('asset_face_audit')
.select(['asset_face_audit.id', 'assetFaceId'])
.orderBy('asset_face_audit.id', 'asc')
.leftJoin('asset', 'asset.id', 'asset_face_audit.assetId')
.where('asset.ownerId', '=', userId)
.where('asset_face_audit.deletedAt', '<', sql.raw<Date>("now() - interval '1 millisecond'"))
.$if(!!ack, (qb) => qb.where('asset_face_audit.id', '>', ack!.updateId))
.stream();
}
@GenerateSql({ params: [DummyValue.UUID], stream: true })
getUpserts(userId: string, ack?: SyncAck) {
return this.db
.selectFrom('asset_face')
.select([
'asset_face.id',
'assetId',
'personId',
'imageWidth',
'imageHeight',
'boundingBoxX1',
'boundingBoxY1',
'boundingBoxX2',
'boundingBoxY2',
'sourceType',
'asset_face.updateId',
])
.where('asset_face.updatedAt', '<', sql.raw<Date>("now() - interval '1 millisecond'"))
.$if(!!ack, (qb) => qb.where('asset_face.updateId', '>', ack!.updateId))
.orderBy('asset_face.updateId', 'asc')
.leftJoin('asset', 'asset.id', 'asset_face.assetId')
.where('asset.ownerId', '=', userId)
.stream();
}
}
class AssetExifSync extends BaseSync { class AssetExifSync extends BaseSync {
@GenerateSql({ params: [DummyValue.UUID], stream: true }) @GenerateSql({ params: [DummyValue.UUID], stream: true })
getUpserts(userId: string, ack?: SyncAck) { getUpserts(userId: string, ack?: SyncAck) {

View File

@ -229,3 +229,16 @@ export const user_metadata_audit = registerFunction({
RETURN NULL; RETURN NULL;
END`, END`,
}); });
export const asset_face_audit = registerFunction({
name: 'asset_face_audit',
returnType: 'TRIGGER',
language: 'PLPGSQL',
body: `
BEGIN
INSERT INTO asset_face_audit ("assetFaceId", "assetId")
SELECT "id", "assetId"
FROM OLD;
RETURN NULL;
END`,
});

View File

@ -4,6 +4,7 @@ import {
album_user_after_insert, album_user_after_insert,
album_user_delete_audit, album_user_delete_audit,
asset_delete_audit, asset_delete_audit,
asset_face_audit,
f_concat_ws, f_concat_ws,
f_unaccent, f_unaccent,
immich_uuid_v7, immich_uuid_v7,
@ -27,6 +28,7 @@ import { AlbumTable } from 'src/schema/tables/album.table';
import { ApiKeyTable } from 'src/schema/tables/api-key.table'; import { ApiKeyTable } from 'src/schema/tables/api-key.table';
import { AssetAuditTable } from 'src/schema/tables/asset-audit.table'; import { AssetAuditTable } from 'src/schema/tables/asset-audit.table';
import { AssetExifTable } from 'src/schema/tables/asset-exif.table'; import { AssetExifTable } from 'src/schema/tables/asset-exif.table';
import { AssetFaceAuditTable } from 'src/schema/tables/asset-face-audit.table';
import { AssetFaceTable } from 'src/schema/tables/asset-face.table'; import { AssetFaceTable } from 'src/schema/tables/asset-face.table';
import { AssetFileTable } from 'src/schema/tables/asset-file.table'; import { AssetFileTable } from 'src/schema/tables/asset-file.table';
import { AssetJobStatusTable } from 'src/schema/tables/asset-job-status.table'; import { AssetJobStatusTable } from 'src/schema/tables/asset-job-status.table';
@ -78,6 +80,7 @@ export class ImmichDatabase {
ApiKeyTable, ApiKeyTable,
AssetAuditTable, AssetAuditTable,
AssetFaceTable, AssetFaceTable,
AssetFaceAuditTable,
AssetJobStatusTable, AssetJobStatusTable,
AssetTable, AssetTable,
AssetFileTable, AssetFileTable,
@ -132,6 +135,7 @@ export class ImmichDatabase {
stack_delete_audit, stack_delete_audit,
person_delete_audit, person_delete_audit,
user_metadata_audit, user_metadata_audit,
asset_face_audit,
]; ];
enum = [assets_status_enum, asset_face_source_type, asset_visibility_enum]; enum = [assets_status_enum, asset_face_source_type, asset_visibility_enum];
@ -158,6 +162,7 @@ export interface DB {
asset: AssetTable; asset: AssetTable;
asset_exif: AssetExifTable; asset_exif: AssetExifTable;
asset_face: AssetFaceTable; asset_face: AssetFaceTable;
asset_face_audit: AssetFaceAuditTable;
asset_file: AssetFileTable; asset_file: AssetFileTable;
asset_job_status: AssetJobStatusTable; asset_job_status: AssetJobStatusTable;
asset_audit: AssetAuditTable; asset_audit: AssetAuditTable;

View File

@ -0,0 +1,52 @@
import { Kysely, sql } from 'kysely';
export async function up(db: Kysely<any>): Promise<void> {
await sql`CREATE OR REPLACE FUNCTION asset_face_audit()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS $$
BEGIN
INSERT INTO asset_face_audit ("assetFaceId", "assetId")
SELECT "id", "assetId"
FROM OLD;
RETURN NULL;
END
$$;`.execute(db);
await sql`CREATE TABLE "asset_face_audit" (
"id" uuid NOT NULL DEFAULT immich_uuid_v7(),
"assetFaceId" uuid NOT NULL,
"assetId" uuid NOT NULL,
"deletedAt" timestamp with time zone NOT NULL DEFAULT clock_timestamp(),
CONSTRAINT "asset_face_audit_pkey" PRIMARY KEY ("id")
);`.execute(db);
await sql`CREATE INDEX "asset_face_audit_assetFaceId_idx" ON "asset_face_audit" ("assetFaceId");`.execute(db);
await sql`CREATE INDEX "asset_face_audit_assetId_idx" ON "asset_face_audit" ("assetId");`.execute(db);
await sql`CREATE INDEX "asset_face_audit_deletedAt_idx" ON "asset_face_audit" ("deletedAt");`.execute(db);
await sql`ALTER TABLE "asset_face" ADD "updatedAt" timestamp with time zone NOT NULL DEFAULT now();`.execute(db);
await sql`ALTER TABLE "asset_face" ADD "updateId" uuid NOT NULL DEFAULT immich_uuid_v7();`.execute(db);
await sql`CREATE OR REPLACE TRIGGER "asset_face_audit"
AFTER DELETE ON "asset_face"
REFERENCING OLD TABLE AS "old"
FOR EACH STATEMENT
WHEN (pg_trigger_depth() = 0)
EXECUTE FUNCTION asset_face_audit();`.execute(db);
await sql`CREATE OR REPLACE TRIGGER "asset_face_updatedAt"
BEFORE UPDATE ON "asset_face"
FOR EACH ROW
EXECUTE FUNCTION updated_at();`.execute(db);
await sql`INSERT INTO "migration_overrides" ("name", "value") VALUES ('function_asset_face_audit', '{"type":"function","name":"asset_face_audit","sql":"CREATE OR REPLACE FUNCTION asset_face_audit()\\n RETURNS TRIGGER\\n LANGUAGE PLPGSQL\\n AS $$\\n BEGIN\\n INSERT INTO asset_face_audit (\\"assetFaceId\\", \\"assetId\\")\\n SELECT \\"id\\", \\"assetId\\"\\n FROM OLD;\\n RETURN NULL;\\n END\\n $$;"}'::jsonb);`.execute(db);
await sql`INSERT INTO "migration_overrides" ("name", "value") VALUES ('trigger_asset_face_audit', '{"type":"trigger","name":"asset_face_audit","sql":"CREATE OR REPLACE TRIGGER \\"asset_face_audit\\"\\n AFTER DELETE ON \\"asset_face\\"\\n REFERENCING OLD TABLE AS \\"old\\"\\n FOR EACH STATEMENT\\n WHEN (pg_trigger_depth() = 0)\\n EXECUTE FUNCTION asset_face_audit();"}'::jsonb);`.execute(db);
await sql`INSERT INTO "migration_overrides" ("name", "value") VALUES ('trigger_asset_face_updatedAt', '{"type":"trigger","name":"asset_face_updatedAt","sql":"CREATE OR REPLACE TRIGGER \\"asset_face_updatedAt\\"\\n BEFORE UPDATE ON \\"asset_face\\"\\n FOR EACH ROW\\n EXECUTE FUNCTION updated_at();"}'::jsonb);`.execute(db);
}
export async function down(db: Kysely<any>): Promise<void> {
await sql`DROP TRIGGER "asset_face_audit" ON "asset_face";`.execute(db);
await sql`DROP TRIGGER "asset_face_updatedAt" ON "asset_face";`.execute(db);
await sql`ALTER TABLE "asset_face" DROP COLUMN "updatedAt";`.execute(db);
await sql`ALTER TABLE "asset_face" DROP COLUMN "updateId";`.execute(db);
await sql`DROP TABLE "asset_face_audit";`.execute(db);
await sql`DROP FUNCTION asset_face_audit;`.execute(db);
await sql`DELETE FROM "migration_overrides" WHERE "name" = 'function_asset_face_audit';`.execute(db);
await sql`DELETE FROM "migration_overrides" WHERE "name" = 'trigger_asset_face_audit';`.execute(db);
await sql`DELETE FROM "migration_overrides" WHERE "name" = 'trigger_asset_face_updatedAt';`.execute(db);
}

View File

@ -0,0 +1,17 @@
import { PrimaryGeneratedUuidV7Column } from 'src/decorators';
import { Column, CreateDateColumn, Generated, Table, Timestamp } from 'src/sql-tools';
@Table('asset_face_audit')
export class AssetFaceAuditTable {
@PrimaryGeneratedUuidV7Column()
id!: Generated<string>;
@Column({ type: 'uuid', index: true })
assetFaceId!: string;
@Column({ type: 'uuid', index: true })
assetId!: string;
@CreateDateColumn({ default: () => 'clock_timestamp()', index: true })
deletedAt!: Generated<Timestamp>;
}

View File

@ -1,8 +1,11 @@
import { UpdatedAtTrigger, UpdateIdColumn } from 'src/decorators';
import { SourceType } from 'src/enum'; import { SourceType } from 'src/enum';
import { asset_face_source_type } from 'src/schema/enums'; import { asset_face_source_type } from 'src/schema/enums';
import { asset_face_audit } from 'src/schema/functions';
import { AssetTable } from 'src/schema/tables/asset.table'; import { AssetTable } from 'src/schema/tables/asset.table';
import { PersonTable } from 'src/schema/tables/person.table'; import { PersonTable } from 'src/schema/tables/person.table';
import { import {
AfterDeleteTrigger,
Column, Column,
DeleteDateColumn, DeleteDateColumn,
ForeignKeyColumn, ForeignKeyColumn,
@ -11,9 +14,17 @@ import {
PrimaryGeneratedColumn, PrimaryGeneratedColumn,
Table, Table,
Timestamp, Timestamp,
UpdateDateColumn,
} from 'src/sql-tools'; } from 'src/sql-tools';
@Table({ name: 'asset_face' }) @Table({ name: 'asset_face' })
@UpdatedAtTrigger('asset_face_updatedAt')
@AfterDeleteTrigger({
scope: 'statement',
function: asset_face_audit,
referencingOldTableAs: 'old',
when: 'pg_trigger_depth() = 0',
})
// schemaFromDatabase does not preserve column order // schemaFromDatabase does not preserve column order
@Index({ name: 'asset_face_assetId_personId_idx', columns: ['assetId', 'personId'] }) @Index({ name: 'asset_face_assetId_personId_idx', columns: ['assetId', 'personId'] })
@Index({ columns: ['personId', 'assetId'] }) @Index({ columns: ['personId', 'assetId'] })
@ -61,4 +72,10 @@ export class AssetFaceTable {
@DeleteDateColumn() @DeleteDateColumn()
deletedAt!: Timestamp | null; deletedAt!: Timestamp | null;
@UpdateDateColumn()
updatedAt!: Generated<Timestamp>;
@UpdateIdColumn()
updateId!: Generated<string>;
} }

View File

@ -70,6 +70,7 @@ export const SYNC_TYPES_ORDER = [
SyncRequestType.MemoriesV1, SyncRequestType.MemoriesV1,
SyncRequestType.MemoryToAssetsV1, SyncRequestType.MemoryToAssetsV1,
SyncRequestType.PeopleV1, SyncRequestType.PeopleV1,
SyncRequestType.AssetFacesV1,
SyncRequestType.UserMetadataV1, SyncRequestType.UserMetadataV1,
]; ];
@ -156,6 +157,7 @@ export class SyncService extends BaseService {
[SyncRequestType.StacksV1]: () => this.syncStackV1(response, checkpointMap, auth), [SyncRequestType.StacksV1]: () => this.syncStackV1(response, checkpointMap, auth),
[SyncRequestType.PartnerStacksV1]: () => this.syncPartnerStackV1(response, checkpointMap, auth, session.id), [SyncRequestType.PartnerStacksV1]: () => this.syncPartnerStackV1(response, checkpointMap, auth, session.id),
[SyncRequestType.PeopleV1]: () => this.syncPeopleV1(response, checkpointMap, auth), [SyncRequestType.PeopleV1]: () => this.syncPeopleV1(response, checkpointMap, auth),
[SyncRequestType.AssetFacesV1]: async () => this.syncAssetFacesV1(response, checkpointMap, auth),
[SyncRequestType.UserMetadataV1]: () => this.syncUserMetadataV1(response, checkpointMap, auth), [SyncRequestType.UserMetadataV1]: () => this.syncUserMetadataV1(response, checkpointMap, auth),
}; };
@ -606,6 +608,20 @@ export class SyncService extends BaseService {
} }
} }
private async syncAssetFacesV1(response: Writable, checkpointMap: CheckpointMap, auth: AuthDto) {
const deleteType = SyncEntityType.AssetFaceDeleteV1;
const deletes = this.syncRepository.assetFace.getDeletes(auth.user.id, checkpointMap[deleteType]);
for await (const { id, ...data } of deletes) {
send(response, { type: deleteType, ids: [id], data });
}
const upsertType = SyncEntityType.AssetFaceV1;
const upserts = this.syncRepository.assetFace.getUpserts(auth.user.id, checkpointMap[upsertType]);
for await (const { updateId, ...data } of upserts) {
send(response, { type: upsertType, ids: [updateId], data });
}
}
private async syncUserMetadataV1(response: Writable, checkpointMap: CheckpointMap, auth: AuthDto) { private async syncUserMetadataV1(response: Writable, checkpointMap: CheckpointMap, auth: AuthDto) {
const deleteType = SyncEntityType.UserMetadataDeleteV1; const deleteType = SyncEntityType.UserMetadataDeleteV1;
const deletes = this.syncRepository.userMetadata.getDeletes(auth.user.id, checkpointMap[deleteType]); const deletes = this.syncRepository.userMetadata.getDeletes(auth.user.id, checkpointMap[deleteType]);

View File

@ -23,6 +23,8 @@ export const faceStub = {
sourceType: SourceType.MachineLearning, sourceType: SourceType.MachineLearning,
faceSearch: { faceId: 'assetFaceId1', embedding: '[1, 2, 3, 4]' }, faceSearch: { faceId: 'assetFaceId1', embedding: '[1, 2, 3, 4]' },
deletedAt: new Date(), deletedAt: new Date(),
updatedAt: new Date('2023-01-01T00:00:00Z'),
updateId: '0d1173e3-4d80-4d76-b41e-57d56de21125',
}), }),
primaryFace1: Object.freeze({ primaryFace1: Object.freeze({
id: 'assetFaceId2', id: 'assetFaceId2',
@ -39,6 +41,8 @@ export const faceStub = {
sourceType: SourceType.MachineLearning, sourceType: SourceType.MachineLearning,
faceSearch: { faceId: 'assetFaceId2', embedding: '[1, 2, 3, 4]' }, faceSearch: { faceId: 'assetFaceId2', embedding: '[1, 2, 3, 4]' },
deletedAt: null, deletedAt: null,
updatedAt: new Date('2023-01-01T00:00:00Z'),
updateId: '0d1173e3-4d80-4d76-b41e-57d56de21125',
}), }),
mergeFace1: Object.freeze({ mergeFace1: Object.freeze({
id: 'assetFaceId3', id: 'assetFaceId3',
@ -55,6 +59,8 @@ export const faceStub = {
sourceType: SourceType.MachineLearning, sourceType: SourceType.MachineLearning,
faceSearch: { faceId: 'assetFaceId3', embedding: '[1, 2, 3, 4]' }, faceSearch: { faceId: 'assetFaceId3', embedding: '[1, 2, 3, 4]' },
deletedAt: null, deletedAt: null,
updatedAt: new Date('2023-01-01T00:00:00Z'),
updateId: '0d1173e3-4d80-4d76-b41e-57d56de21125',
}), }),
noPerson1: Object.freeze({ noPerson1: Object.freeze({
id: 'assetFaceId8', id: 'assetFaceId8',
@ -71,6 +77,8 @@ export const faceStub = {
sourceType: SourceType.MachineLearning, sourceType: SourceType.MachineLearning,
faceSearch: { faceId: 'assetFaceId8', embedding: '[1, 2, 3, 4]' }, faceSearch: { faceId: 'assetFaceId8', embedding: '[1, 2, 3, 4]' },
deletedAt: null, deletedAt: null,
updatedAt: new Date('2023-01-01T00:00:00Z'),
updateId: '0d1173e3-4d80-4d76-b41e-57d56de21125',
}), }),
noPerson2: Object.freeze({ noPerson2: Object.freeze({
id: 'assetFaceId9', id: 'assetFaceId9',
@ -87,6 +95,8 @@ export const faceStub = {
sourceType: SourceType.MachineLearning, sourceType: SourceType.MachineLearning,
faceSearch: { faceId: 'assetFaceId9', embedding: '[1, 2, 3, 4]' }, faceSearch: { faceId: 'assetFaceId9', embedding: '[1, 2, 3, 4]' },
deletedAt: null, deletedAt: null,
updatedAt: new Date('2023-01-01T00:00:00Z'),
updateId: '0d1173e3-4d80-4d76-b41e-57d56de21125',
}), }),
fromExif1: Object.freeze({ fromExif1: Object.freeze({
id: 'assetFaceId9', id: 'assetFaceId9',
@ -102,6 +112,8 @@ export const faceStub = {
imageWidth: 400, imageWidth: 400,
sourceType: SourceType.Exif, sourceType: SourceType.Exif,
deletedAt: null, deletedAt: null,
updatedAt: new Date('2023-01-01T00:00:00Z'),
updateId: '0d1173e3-4d80-4d76-b41e-57d56de21125',
}), }),
fromExif2: Object.freeze({ fromExif2: Object.freeze({
id: 'assetFaceId9', id: 'assetFaceId9',
@ -117,6 +129,8 @@ export const faceStub = {
imageWidth: 1024, imageWidth: 1024,
sourceType: SourceType.Exif, sourceType: SourceType.Exif,
deletedAt: null, deletedAt: null,
updatedAt: new Date('2023-01-01T00:00:00Z'),
updateId: '0d1173e3-4d80-4d76-b41e-57d56de21125',
}), }),
withBirthDate: Object.freeze({ withBirthDate: Object.freeze({
id: 'assetFaceId10', id: 'assetFaceId10',
@ -132,5 +146,7 @@ export const faceStub = {
imageWidth: 1024, imageWidth: 1024,
sourceType: SourceType.MachineLearning, sourceType: SourceType.MachineLearning,
deletedAt: null, deletedAt: null,
updatedAt: new Date('2023-01-01T00:00:00Z'),
updateId: '0d1173e3-4d80-4d76-b41e-57d56de21125',
}), }),
}; };

View File

@ -154,6 +154,12 @@ export class MediumTestContext<S extends BaseService = BaseService> {
return { asset, result }; return { asset, result };
} }
async newAssetFace(dto: Partial<Insertable<AssetFace>> & { assetId: string }) {
const assetFace = mediumFactory.assetFaceInsert(dto);
const result = await this.get(PersonRepository).createAssetFace(assetFace);
return { assetFace, result };
}
async newMemory(dto: Partial<Insertable<MemoryTable>> = {}) { async newMemory(dto: Partial<Insertable<MemoryTable>> = {}) {
const memory = mediumFactory.memoryInsert(dto); const memory = mediumFactory.memoryInsert(dto);
const result = await this.get(MemoryRepository).create(memory, new Set<string>()); const result = await this.get(MemoryRepository).create(memory, new Set<string>());

View File

@ -0,0 +1,92 @@
import { Kysely } from 'kysely';
import { SyncEntityType, SyncRequestType } from 'src/enum';
import { PersonRepository } from 'src/repositories/person.repository';
import { DB } from 'src/schema';
import { SyncTestContext } from 'test/medium.factory';
import { factory } from 'test/small.factory';
import { getKyselyDB } from 'test/utils';
let defaultDatabase: Kysely<DB>;
const setup = async (db?: Kysely<DB>) => {
const ctx = new SyncTestContext(db || defaultDatabase);
const { auth, user, session } = await ctx.newSyncAuthUser();
return { auth, user, session, ctx };
};
beforeAll(async () => {
defaultDatabase = await getKyselyDB();
});
describe(SyncEntityType.AssetFaceV1, () => {
it('should detect and sync the first asset face', async () => {
const { auth, ctx } = await setup();
const { asset } = await ctx.newAsset({ ownerId: auth.user.id });
const { person } = await ctx.newPerson({ ownerId: auth.user.id });
const { assetFace } = await ctx.newAssetFace({ assetId: asset.id, personId: person.id });
const response = await ctx.syncStream(auth, [SyncRequestType.AssetFacesV1]);
expect(response).toHaveLength(1);
expect(response).toEqual([
{
ack: expect.any(String),
data: expect.objectContaining({
id: assetFace.id,
assetId: asset.id,
personId: person.id,
imageWidth: assetFace.imageWidth,
imageHeight: assetFace.imageHeight,
boundingBoxX1: assetFace.boundingBoxX1,
boundingBoxY1: assetFace.boundingBoxY1,
boundingBoxX2: assetFace.boundingBoxX2,
boundingBoxY2: assetFace.boundingBoxY2,
sourceType: assetFace.sourceType,
}),
type: 'AssetFaceV1',
},
]);
await ctx.syncAckAll(auth, response);
await expect(ctx.syncStream(auth, [SyncRequestType.AssetFacesV1])).resolves.toEqual([]);
});
it('should detect and sync a deleted asset face', async () => {
const { auth, ctx } = await setup();
const personRepo = ctx.get(PersonRepository);
const { asset } = await ctx.newAsset({ ownerId: auth.user.id });
const { assetFace } = await ctx.newAssetFace({ assetId: asset.id });
await personRepo.deleteAssetFace(assetFace.id);
const response = await ctx.syncStream(auth, [SyncRequestType.AssetFacesV1]);
expect(response).toHaveLength(1);
expect(response).toEqual([
{
ack: expect.any(String),
data: {
assetFaceId: assetFace.id,
},
type: 'AssetFaceDeleteV1',
},
]);
await ctx.syncAckAll(auth, response);
await expect(ctx.syncStream(auth, [SyncRequestType.AssetFacesV1])).resolves.toEqual([]);
});
it('should not sync an asset face or asset face delete for an unrelated user', async () => {
const { auth, ctx } = await setup();
const personRepo = ctx.get(PersonRepository);
const { user: user2 } = await ctx.newUser();
const { session } = await ctx.newSession({ userId: user2.id });
const { asset } = await ctx.newAsset({ ownerId: user2.id });
const { assetFace } = await ctx.newAssetFace({ assetId: asset.id });
const auth2 = factory.auth({ session, user: user2 });
expect(await ctx.syncStream(auth2, [SyncRequestType.AssetFacesV1])).toHaveLength(1);
expect(await ctx.syncStream(auth, [SyncRequestType.AssetFacesV1])).toHaveLength(0);
await personRepo.deleteAssetFace(assetFace.id);
expect(await ctx.syncStream(auth2, [SyncRequestType.AssetFacesV1])).toHaveLength(1);
expect(await ctx.syncStream(auth, [SyncRequestType.AssetFacesV1])).toHaveLength(0);
});
});

View File

@ -31,7 +31,6 @@ describe(SyncEntityType.PersonV1, () => {
data: expect.objectContaining({ data: expect.objectContaining({
id: person.id, id: person.id,
name: person.name, name: person.name,
thumbnailPath: person.thumbnailPath,
isHidden: person.isHidden, isHidden: person.isHidden,
birthDate: person.birthDate, birthDate: person.birthDate,
faceAssetId: person.faceAssetId, faceAssetId: person.faceAssetId,