Skip to content

High performance self-hosted photo and video management solution.

fix(server): prevent cross-library motion photo linking, made getByChecksum library specific (#8719)

Kevin Huangec76e5ef237f
diff --git a/server/src/interfaces/asset.interface.ts b/server/src/interfaces/asset.interface.ts
index 008931566b..eab392a586 100644
--- a/server/src/interfaces/asset.interface.ts
+++ b/server/src/interfaces/asset.interface.ts
@@ -146,7 +146,7 @@ export interface IAssetRepository {
): Promise<AssetEntity[]>;
getByIdsWithAllRelations(ids: string[]): Promise<AssetEntity[]>;
getByDayOfYear(ownerIds: string[], monthDay: MonthDay): Promise<AssetEntity[]>;
- getByChecksum(userId: string, checksum: Buffer): Promise<AssetEntity | null>;
+ getByChecksum(libraryId: string, checksum: Buffer): Promise<AssetEntity | null>;
getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated<AssetEntity>;
getByUserId(pagination: PaginationOptions, userId: string, options?: AssetSearchOptions): Paginated<AssetEntity>;
getById(id: string, relations?: FindOptionsRelations<AssetEntity>): Promise<AssetEntity | null>;
diff --git a/server/src/queries/asset.repository.sql b/server/src/queries/asset.repository.sql
index 6f0e8cd5e3..d8edfdb12c 100644
--- a/server/src/queries/asset.repository.sql
+++ b/server/src/queries/asset.repository.sql
@@ -464,7 +464,7 @@ FROM
WHERE
(
(
- ("AssetEntity"."ownerId" = $1)
+ ("AssetEntity"."libraryId" = $1)
AND ("AssetEntity"."checksum" = $2)
)
)
diff --git a/server/src/repositories/asset.repository.ts b/server/src/repositories/asset.repository.ts
index e6389c2e56..b7ed3e4f00 100644
--- a/server/src/repositories/asset.repository.ts
+++ b/server/src/repositories/asset.repository.ts
@@ -265,8 +265,8 @@ export class AssetRepository implements IAssetRepository {
}
@GenerateSql({ params: [DummyValue.UUID, DummyValue.BUFFER] })
- getByChecksum(userId: string, checksum: Buffer): Promise<AssetEntity | null> {
- return this.repository.findOne({ where: { ownerId: userId, checksum } });
+ getByChecksum(libraryId: string, checksum: Buffer): Promise<AssetEntity | null> {
+ return this.repository.findOne({ where: { libraryId, checksum } });
}
findLivePhotoMatch(options: LivePhotoSearchOptions): Promise<AssetEntity | null> {
diff --git a/server/src/services/metadata.service.ts b/server/src/services/metadata.service.ts
index 9b249a49f4..327bd7b665 100644
--- a/server/src/services/metadata.service.ts
+++ b/server/src/services/metadata.service.ts
@@ -405,7 +405,7 @@ export class MetadataService {
}
const checksum = this.cryptoRepository.hashSha1(video);
- let motionAsset = await this.assetRepository.getByChecksum(asset.ownerId, checksum);
+ let motionAsset = await this.assetRepository.getByChecksum(asset.libraryId, checksum);
if (motionAsset) {
this.logger.debug(
`Asset ${asset.id}'s motion photo video with checksum ${checksum.toString(