diff --git a/mobile/lib/infrastructure/repositories/sync_stream.repository.dart b/mobile/lib/infrastructure/repositories/sync_stream.repository.dart index f1abcfed27..cc6c1e3e7a 100644 --- a/mobile/lib/infrastructure/repositories/sync_stream.repository.dart +++ b/mobile/lib/infrastructure/repositories/sync_stream.repository.dart @@ -165,7 +165,7 @@ class DriftSyncStreamRepository extends DriftDatabaseRepository _db.batch((batch) { for (final asset in data) { final companion = RemoteAssetEntityCompanion( - name: const Value(''), // TODO: Needed from the server + name: Value(asset.originalFileName), type: Value(asset.type.toAssetType()), createdAt: Value.absentIfNull(asset.fileCreatedAt), updatedAt: Value.absentIfNull(asset.fileModifiedAt), diff --git a/mobile/openapi/lib/model/sync_asset_v1.dart b/mobile/openapi/lib/model/sync_asset_v1.dart index 6f9d7d7eaf..9f91eed68e 100644 --- a/mobile/openapi/lib/model/sync_asset_v1.dart +++ b/mobile/openapi/lib/model/sync_asset_v1.dart @@ -21,6 +21,7 @@ class SyncAssetV1 { required this.isFavorite, required this.isVisible, required this.localDateTime, + required this.originalFileName, required this.ownerId, required this.thumbhash, required this.type, @@ -42,6 +43,8 @@ class SyncAssetV1 { DateTime? localDateTime; + String originalFileName; + String ownerId; String? thumbhash; @@ -58,6 +61,7 @@ class SyncAssetV1 { other.isFavorite == isFavorite && other.isVisible == isVisible && other.localDateTime == localDateTime && + other.originalFileName == originalFileName && other.ownerId == ownerId && other.thumbhash == thumbhash && other.type == type; @@ -73,12 +77,13 @@ class SyncAssetV1 { (isFavorite.hashCode) + (isVisible.hashCode) + (localDateTime == null ? 0 : localDateTime!.hashCode) + + (originalFileName.hashCode) + (ownerId.hashCode) + (thumbhash == null ? 0 : thumbhash!.hashCode) + (type.hashCode); @override - String toString() => 'SyncAssetV1[checksum=$checksum, deletedAt=$deletedAt, fileCreatedAt=$fileCreatedAt, fileModifiedAt=$fileModifiedAt, id=$id, isFavorite=$isFavorite, isVisible=$isVisible, localDateTime=$localDateTime, ownerId=$ownerId, thumbhash=$thumbhash, type=$type]'; + String toString() => 'SyncAssetV1[checksum=$checksum, deletedAt=$deletedAt, fileCreatedAt=$fileCreatedAt, fileModifiedAt=$fileModifiedAt, id=$id, isFavorite=$isFavorite, isVisible=$isVisible, localDateTime=$localDateTime, originalFileName=$originalFileName, ownerId=$ownerId, thumbhash=$thumbhash, type=$type]'; Map<String, dynamic> toJson() { final json = <String, dynamic>{}; @@ -106,6 +111,7 @@ class SyncAssetV1 { } else { // json[r'localDateTime'] = null; } + json[r'originalFileName'] = this.originalFileName; json[r'ownerId'] = this.ownerId; if (this.thumbhash != null) { json[r'thumbhash'] = this.thumbhash; @@ -133,6 +139,7 @@ class SyncAssetV1 { isFavorite: mapValueOfType<bool>(json, r'isFavorite')!, isVisible: mapValueOfType<bool>(json, r'isVisible')!, localDateTime: mapDateTime(json, r'localDateTime', r''), + originalFileName: mapValueOfType<String>(json, r'originalFileName')!, ownerId: mapValueOfType<String>(json, r'ownerId')!, thumbhash: mapValueOfType<String>(json, r'thumbhash'), type: SyncAssetV1TypeEnum.fromJson(json[r'type'])!, @@ -191,6 +198,7 @@ class SyncAssetV1 { 'isFavorite', 'isVisible', 'localDateTime', + 'originalFileName', 'ownerId', 'thumbhash', 'type', diff --git a/open-api/immich-openapi-specs.json b/open-api/immich-openapi-specs.json index 4e8e7ab834..c322420e59 100644 --- a/open-api/immich-openapi-specs.json +++ b/open-api/immich-openapi-specs.json @@ -12234,6 +12234,9 @@ "nullable": true, "type": "string" }, + "originalFileName": { + "type": "string" + }, "ownerId": { "type": "string" }, @@ -12260,6 +12263,7 @@ "isFavorite", "isVisible", "localDateTime", + "originalFileName", "ownerId", "thumbhash", "type" diff --git a/server/src/database.ts b/server/src/database.ts index 27094958ed..32ecaa2a76 100644 --- a/server/src/database.ts +++ b/server/src/database.ts @@ -326,6 +326,7 @@ export const columns = { syncAsset: [ 'id', 'ownerId', + 'originalFileName', 'thumbhash', 'checksum', 'fileCreatedAt', diff --git a/server/src/dtos/sync.dto.ts b/server/src/dtos/sync.dto.ts index a035f8ecb9..b9d3d2f17c 100644 --- a/server/src/dtos/sync.dto.ts +++ b/server/src/dtos/sync.dto.ts @@ -59,6 +59,7 @@ export class SyncPartnerDeleteV1 { export class SyncAssetV1 { id!: string; ownerId!: string; + originalFileName!: string; thumbhash!: string | null; checksum!: string; fileCreatedAt!: Date | null; diff --git a/server/src/queries/sync.repository.sql b/server/src/queries/sync.repository.sql index e08335d9f1..f442510a3c 100644 --- a/server/src/queries/sync.repository.sql +++ b/server/src/queries/sync.repository.sql @@ -76,6 +76,7 @@ order by select "id", "ownerId", + "originalFileName", "thumbhash", "checksum", "fileCreatedAt", @@ -98,6 +99,7 @@ order by select "id", "ownerId", + "originalFileName", "thumbhash", "checksum", "fileCreatedAt", diff --git a/server/test/medium/specs/services/sync.service.spec.ts b/server/test/medium/specs/services/sync.service.spec.ts index 98df296cbf..72c5e3d893 100644 --- a/server/test/medium/specs/services/sync.service.spec.ts +++ b/server/test/medium/specs/services/sync.service.spec.ts @@ -424,12 +424,14 @@ describe(SyncService.name, () => { it('should detect and sync the first asset', async () => { const { auth, sut, getRepository, testSync } = await setup(); + const originalFileName = 'firstAsset'; const checksum = '1115vHcVkZzNp3Q9G+FEA0nu6zUbGb4Tj4UOXkN0wRA='; const thumbhash = '2225vHcVkZzNp3Q9G+FEA0nu6zUbGb4Tj4UOXkN0wRA='; const date = new Date().toISOString(); const assetRepo = getRepository('asset'); const asset = mediumFactory.assetInsert({ + originalFileName, ownerId: auth.user.id, checksum: Buffer.from(checksum, 'base64'), thumbhash: Buffer.from(thumbhash, 'base64'), @@ -449,6 +451,7 @@ describe(SyncService.name, () => { ack: expect.any(String), data: { id: asset.id, + originalFileName, ownerId: asset.ownerId, thumbhash, checksum, @@ -534,6 +537,7 @@ describe(SyncService.name, () => { it('should detect and sync the first partner asset', async () => { const { auth, sut, getRepository, testSync } = await setup(); + const originalFileName = 'firstPartnerAsset'; const checksum = '1115vHcVkZzNp3Q9G+FEA0nu6zUbGb4Tj4UOXkN0wRA='; const thumbhash = '2225vHcVkZzNp3Q9G+FEA0nu6zUbGb4Tj4UOXkN0wRA='; const date = new Date().toISOString(); @@ -545,6 +549,7 @@ describe(SyncService.name, () => { const assetRepo = getRepository('asset'); const asset = mediumFactory.assetInsert({ ownerId: user2.id, + originalFileName, checksum: Buffer.from(checksum, 'base64'), thumbhash: Buffer.from(thumbhash, 'base64'), fileCreatedAt: date, @@ -567,6 +572,7 @@ describe(SyncService.name, () => { data: { id: asset.id, ownerId: asset.ownerId, + originalFileName, thumbhash, checksum, deletedAt: null,