Skip to content

High performance self-hosted photo and video management solution.

fix: emit album update event when uploading assets through shared link (#29757)

Daniel Dietzlerfea0db02f398
diff --git a/server/src/services/asset-media.service.ts b/server/src/services/asset-media.service.ts
index de8c2bbc91..1da5146d91 100644
--- a/server/src/services/asset-media.service.ts
+++ b/server/src/services/asset-media.service.ts
@@ -342,9 +342,20 @@ export class AssetMediaService extends BaseService {
}
private async addToSharedLink(sharedLink: AuthSharedLink, assetId: string) {
- await (sharedLink.albumId
- ? this.albumRepository.addAssetIds(sharedLink.albumId, [assetId])
- : this.sharedLinkRepository.addAssets(sharedLink.id, [assetId]));
+ if (!sharedLink.albumId) {
+ await this.sharedLinkRepository.addAssets(sharedLink.id, [assetId]);
+ return;
+ }
+
+ const album = await this.albumRepository.getById(sharedLink.albumId, { withAssets: false });
+ if (!album) {
+ return;
+ }
+
+ await this.albumRepository.addAssetIds(album.id, [assetId]);
+ for (const { user } of album.albumUsers) {
+ await this.eventRepository.emit('AlbumUpdate', { id: album.id, recipientId: user.id });
+ }
}
private requireQuota(auth: AuthDto, size: number) {
diff --git a/server/test/medium/specs/services/asset-media.service.spec.ts b/server/test/medium/specs/services/asset-media.service.spec.ts
index e9395bfebf..2d3546d9b0 100644
--- a/server/test/medium/specs/services/asset-media.service.spec.ts
+++ b/server/test/medium/specs/services/asset-media.service.spec.ts
@@ -213,6 +213,11 @@ describe(AssetService.name, () => {
const assets = [...result];
expect(assets).toHaveLength(1);
expect(assets[0]).toEqual(response.id);
+
+ expect(ctx.getMock(EventRepository).emit).toHaveBeenCalledWith('AlbumUpdate', {
+ id: album.id,
+ recipientId: user.id,
+ });
});
it('should handle adding a duplicate asset to an album shared link', async () => {