Skip to content

Commit

Permalink
fix(server): do not match live photos across libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 committed Aug 20, 2024
1 parent fd225e7 commit dab5fcd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/src/interfaces/asset.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface AssetStatsOptions {

export interface LivePhotoSearchOptions {
ownerId: string;
libraryId?: string | null;
livePhotoCID: string;
otherAssetId: string;
type: AssetType;
Expand Down
3 changes: 2 additions & 1 deletion server/src/repositories/asset.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,13 @@ export class AssetRepository implements IAssetRepository {
}

findLivePhotoMatch(options: LivePhotoSearchOptions): Promise<AssetEntity | null> {
const { ownerId, otherAssetId, livePhotoCID, type } = options;
const { ownerId, libraryId, otherAssetId, livePhotoCID, type } = options;

return this.repository.findOne({
where: {
id: Not(otherAssetId),
ownerId,
libraryId: libraryId || IsNull(),
type,
exifInfo: {
livePhotoCID,
Expand Down
23 changes: 23 additions & 0 deletions server/src/services/metadata.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,29 @@ describe(MetadataService.name, () => {
assetStub.livePhotoMotionAsset.id,
);
});

it('should search by libraryId', async () => {
assetMock.getByIds.mockResolvedValue([
{
...assetStub.livePhotoStillAsset,
libraryId: 'library-id',
exifInfo: { livePhotoCID: 'CID' } as ExifEntity,
},
]);
assetMock.findLivePhotoMatch.mockResolvedValue(null);

await expect(sut.handleLivePhotoLinking({ id: assetStub.livePhotoStillAsset.id })).resolves.toBe(
JobStatus.SKIPPED,
);

expect(assetMock.findLivePhotoMatch).toHaveBeenCalledWith({
ownerId: 'user-id',
otherAssetId: 'live-photo-still-asset',
livePhotoCID: 'CID',
libraryId: 'library-id',
type: 'VIDEO',
});
});
});

describe('handleQueueMetadataExtraction', () => {
Expand Down
1 change: 1 addition & 0 deletions server/src/services/metadata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export class MetadataService {
const match = await this.assetRepository.findLivePhotoMatch({
livePhotoCID: asset.exifInfo.livePhotoCID,
ownerId: asset.ownerId,
libraryId: asset.libraryId,
otherAssetId: asset.id,
type: otherType,
});
Expand Down

0 comments on commit dab5fcd

Please sign in to comment.