From b854a3dd47073890be8dfdbab4a1be2cda372dc1 Mon Sep 17 00:00:00 2001 From: shenlong <139912620+shenlong-tanwen@users.noreply.github.com> Date: Fri, 30 May 2025 20:26:35 +0530 Subject: [PATCH] feat(server): add originalFileName to SyncAssetV1 (#18767) Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Co-authored-by: Alex --- mobile/openapi/lib/model/sync_asset_v1.dart | 10 +++++++++- open-api/immich-openapi-specs.json | 4 ++++ server/src/database.ts | 1 + server/src/dtos/sync.dto.ts | 1 + server/src/queries/sync.repository.sql | 2 ++ server/test/medium/specs/sync/sync-asset.spec.ts | 3 +++ .../test/medium/specs/sync/sync-partner-asset.spec.ts | 3 +++ 7 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mobile/openapi/lib/model/sync_asset_v1.dart b/mobile/openapi/lib/model/sync_asset_v1.dart index f5d59b6ae9d..a3aa7365adb 100644 --- a/mobile/openapi/lib/model/sync_asset_v1.dart +++ b/mobile/openapi/lib/model/sync_asset_v1.dart @@ -20,6 +20,7 @@ class SyncAssetV1 { required this.id, required this.isFavorite, required this.localDateTime, + required this.originalFileName, required this.ownerId, required this.thumbhash, required this.type, @@ -40,6 +41,8 @@ class SyncAssetV1 { DateTime? localDateTime; + String originalFileName; + String ownerId; String? thumbhash; @@ -57,6 +60,7 @@ class SyncAssetV1 { other.id == id && other.isFavorite == isFavorite && other.localDateTime == localDateTime && + other.originalFileName == originalFileName && other.ownerId == ownerId && other.thumbhash == thumbhash && other.type == type && @@ -72,13 +76,14 @@ class SyncAssetV1 { (id.hashCode) + (isFavorite.hashCode) + (localDateTime == null ? 0 : localDateTime!.hashCode) + + (originalFileName.hashCode) + (ownerId.hashCode) + (thumbhash == null ? 0 : thumbhash!.hashCode) + (type.hashCode) + (visibility.hashCode); @override - String toString() => 'SyncAssetV1[checksum=$checksum, deletedAt=$deletedAt, fileCreatedAt=$fileCreatedAt, fileModifiedAt=$fileModifiedAt, id=$id, isFavorite=$isFavorite, localDateTime=$localDateTime, ownerId=$ownerId, thumbhash=$thumbhash, type=$type, visibility=$visibility]'; + String toString() => 'SyncAssetV1[checksum=$checksum, deletedAt=$deletedAt, fileCreatedAt=$fileCreatedAt, fileModifiedAt=$fileModifiedAt, id=$id, isFavorite=$isFavorite, localDateTime=$localDateTime, originalFileName=$originalFileName, ownerId=$ownerId, thumbhash=$thumbhash, type=$type, visibility=$visibility]'; Map toJson() { final json = {}; @@ -105,6 +110,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; @@ -132,6 +138,7 @@ class SyncAssetV1 { id: mapValueOfType(json, r'id')!, isFavorite: mapValueOfType(json, r'isFavorite')!, localDateTime: mapDateTime(json, r'localDateTime', r''), + originalFileName: mapValueOfType(json, r'originalFileName')!, ownerId: mapValueOfType(json, r'ownerId')!, thumbhash: mapValueOfType(json, r'thumbhash'), type: SyncAssetV1TypeEnum.fromJson(json[r'type'])!, @@ -190,6 +197,7 @@ class SyncAssetV1 { 'id', 'isFavorite', 'localDateTime', + 'originalFileName', 'ownerId', 'thumbhash', 'type', diff --git a/open-api/immich-openapi-specs.json b/open-api/immich-openapi-specs.json index 410840388f2..538a16e0ad2 100644 --- a/open-api/immich-openapi-specs.json +++ b/open-api/immich-openapi-specs.json @@ -13127,6 +13127,9 @@ "nullable": true, "type": "string" }, + "originalFileName": { + "type": "string" + }, "ownerId": { "type": "string" }, @@ -13161,6 +13164,7 @@ "id", "isFavorite", "localDateTime", + "originalFileName", "ownerId", "thumbhash", "type", diff --git a/server/src/database.ts b/server/src/database.ts index cfccd70b750..4e40e5c241e 100644 --- a/server/src/database.ts +++ b/server/src/database.ts @@ -341,6 +341,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 0043cfb40b4..3e50762c8a8 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 f797f5c0b52..f9565b6effa 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/sync/sync-asset.spec.ts b/server/test/medium/specs/sync/sync-asset.spec.ts index 3cf6d7d30dd..b46ccd97e1d 100644 --- a/server/test/medium/specs/sync/sync-asset.spec.ts +++ b/server/test/medium/specs/sync/sync-asset.spec.ts @@ -23,12 +23,14 @@ describe.concurrent(SyncEntityType.AssetV1, () => { 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'), @@ -48,6 +50,7 @@ describe.concurrent(SyncEntityType.AssetV1, () => { ack: expect.any(String), data: { id: asset.id, + originalFileName, ownerId: asset.ownerId, thumbhash, checksum, diff --git a/server/test/medium/specs/sync/sync-partner-asset.spec.ts b/server/test/medium/specs/sync/sync-partner-asset.spec.ts index 70e31eca4ce..125047b1bf1 100644 --- a/server/test/medium/specs/sync/sync-partner-asset.spec.ts +++ b/server/test/medium/specs/sync/sync-partner-asset.spec.ts @@ -23,6 +23,7 @@ describe.concurrent(SyncRequestType.PartnerAssetsV1, () => { 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(); @@ -34,6 +35,7 @@ describe.concurrent(SyncRequestType.PartnerAssetsV1, () => { const assetRepo = getRepository('asset'); const asset = mediumFactory.assetInsert({ ownerId: user2.id, + originalFileName, checksum: Buffer.from(checksum, 'base64'), thumbhash: Buffer.from(thumbhash, 'base64'), fileCreatedAt: date, @@ -56,6 +58,7 @@ describe.concurrent(SyncRequestType.PartnerAssetsV1, () => { data: { id: asset.id, ownerId: asset.ownerId, + originalFileName, thumbhash, checksum, deletedAt: null,