From d18bc7007a5f1b63cd80202bd3b96af5096b5bb1 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Fri, 30 Aug 2024 17:33:42 -0400 Subject: [PATCH] fix: keyword parsing (#12164) --- server/src/services/metadata.service.spec.ts | 11 +++++++++++ server/src/services/metadata.service.ts | 7 +++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/server/src/services/metadata.service.spec.ts b/server/src/services/metadata.service.spec.ts index 8f44962279..3e3e5e0db1 100644 --- a/server/src/services/metadata.service.spec.ts +++ b/server/src/services/metadata.service.spec.ts @@ -408,6 +408,17 @@ describe(MetadataService.name, () => { expect(tagMock.upsertValue).toHaveBeenCalledWith({ userId: 'user-id', value: 'Parent', parent: undefined }); }); + it('should extract tags from Keywords as a list with a number', async () => { + assetMock.getByIds.mockResolvedValue([assetStub.image]); + metadataMock.readTags.mockResolvedValue({ Keywords: ['Parent', 2024] as any[] }); + tagMock.upsertValue.mockResolvedValue(tagStub.parent); + + await sut.handleMetadataExtraction({ id: assetStub.image.id }); + + expect(tagMock.upsertValue).toHaveBeenCalledWith({ userId: 'user-id', value: 'Parent', parent: undefined }); + expect(tagMock.upsertValue).toHaveBeenCalledWith({ userId: 'user-id', value: '2024', parent: undefined }); + }); + it('should extract hierarchal tags from Keywords', async () => { assetMock.getByIds.mockResolvedValue([assetStub.image]); metadataMock.readTags.mockResolvedValue({ Keywords: 'Parent/Child' }); diff --git a/server/src/services/metadata.service.ts b/server/src/services/metadata.service.ts index 875414d84d..a0a8f9ebef 100644 --- a/server/src/services/metadata.service.ts +++ b/server/src/services/metadata.service.ts @@ -352,22 +352,21 @@ export class MetadataService { } private async applyTagList(asset: AssetEntity, exifTags: ImmichTags) { - const tags: string[] = []; - + const tags: unknown[] = []; if (exifTags.TagsList) { tags.push(...exifTags.TagsList); } if (exifTags.Keywords) { let keywords = exifTags.Keywords; - if (typeof keywords === 'string') { + if (!Array.isArray(keywords)) { keywords = [keywords]; } tags.push(...keywords); } if (tags.length > 0) { - const results = await upsertTags(this.tagRepository, { userId: asset.ownerId, tags }); + const results = await upsertTags(this.tagRepository, { userId: asset.ownerId, tags: tags.map(String) }); const tagIds = results.map((tag) => tag.id); await this.tagRepository.upsertAssetTags({ assetId: asset.id, tagIds }); }