feat(server): Update XMP sidecar search to look for both photo.ext.xmp and photo.xmp (#7813)

* Add support for photo.xmp sidecars

* format

* Add comment

* Proper handling

* Handle mocking better

* Address PR feedback

* Add test coverage if both xmp files exist

* Update server/src/domain/metadata/metadata.service.ts

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>

* Update server/src/domain/metadata/metadata.service.ts

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>

* Update server/src/domain/metadata/metadata.service.ts

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>

---------

Co-authored-by: Alex <alex.tran1502@gmail.com>
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
Kokul Shanmugharajah
2024-03-13 10:14:26 -07:00
committed by GitHub
parent 37e5b91dc2
commit 29c3a826c5
3 changed files with 95 additions and 5 deletions

View File

@@ -646,7 +646,7 @@ describe(MetadataService.name, () => {
expect(assetMock.save).not.toHaveBeenCalled();
});
it('should set sidecar path if exists', async () => {
it('should set sidecar path if exists (sidecar named photo.ext.xmp)', async () => {
assetMock.getByIds.mockResolvedValue([assetStub.sidecar]);
storageMock.checkFileExists.mockResolvedValue(true);
@@ -658,6 +658,41 @@ describe(MetadataService.name, () => {
});
});
it('should set sidecar path if exists (sidecar named photo.xmp)', async () => {
assetMock.getByIds.mockResolvedValue([assetStub.sidecarWithoutExt]);
storageMock.checkFileExists.mockResolvedValueOnce(false);
storageMock.checkFileExists.mockResolvedValueOnce(true);
await expect(sut.handleSidecarSync({ id: assetStub.sidecarWithoutExt.id })).resolves.toBe(true);
expect(storageMock.checkFileExists).toHaveBeenNthCalledWith(
2,
assetStub.sidecarWithoutExt.sidecarPath,
constants.R_OK,
);
expect(assetMock.save).toHaveBeenCalledWith({
id: assetStub.sidecarWithoutExt.id,
sidecarPath: assetStub.sidecarWithoutExt.sidecarPath,
});
});
it('should set sidecar path if exists (two sidecars named photo.ext.xmp and photo.xmp, should pick photo.ext.xmp)', async () => {
assetMock.getByIds.mockResolvedValue([assetStub.sidecar]);
storageMock.checkFileExists.mockResolvedValueOnce(true);
storageMock.checkFileExists.mockResolvedValueOnce(true);
await expect(sut.handleSidecarSync({ id: assetStub.sidecar.id })).resolves.toBe(true);
expect(storageMock.checkFileExists).toHaveBeenNthCalledWith(1, assetStub.sidecar.sidecarPath, constants.R_OK);
expect(storageMock.checkFileExists).toHaveBeenNthCalledWith(
2,
assetStub.sidecarWithoutExt.sidecarPath,
constants.R_OK,
);
expect(assetMock.save).toHaveBeenCalledWith({
id: assetStub.sidecar.id,
sidecarPath: assetStub.sidecar.sidecarPath,
});
});
it('should unset sidecar path if file does not exist anymore', async () => {
assetMock.getByIds.mockResolvedValue([assetStub.sidecar]);
storageMock.checkFileExists.mockResolvedValue(false);