feat(server): server-side events (#5669)

This commit is contained in:
Jason Rasmussen
2023-12-13 12:23:51 -05:00
committed by GitHub
parent 36196f2a5d
commit b34abf25f0
15 changed files with 114 additions and 63 deletions
@@ -20,7 +20,7 @@ import { ImmichFileResponse } from '../domain.util';
import { JobName } from '../job';
import {
AssetStats,
CommunicationEvent,
ClientEvent,
IAssetRepository,
ICommunicationRepository,
ICryptoRepository,
@@ -764,7 +764,7 @@ describe(AssetService.name, () => {
stackParentId: 'parent',
});
expect(communicationMock.send).toHaveBeenCalledWith(CommunicationEvent.ASSET_UPDATE, authStub.user1.user.id, [
expect(communicationMock.send).toHaveBeenCalledWith(ClientEvent.ASSET_UPDATE, authStub.user1.user.id, [
'asset-1',
]);
});
+7 -7
View File
@@ -10,7 +10,7 @@ import { mimeTypes } from '../domain.constant';
import { HumanReadableSize, ImmichFileResponse, usePagination } from '../domain.util';
import { IAssetDeletionJob, ISidecarWriteJob, JOBS_ASSET_PAGINATION_SIZE, JobName } from '../job';
import {
CommunicationEvent,
ClientEvent,
IAccessRepository,
IAssetRepository,
ICommunicationRepository,
@@ -434,7 +434,7 @@ export class AssetService {
}
await this.assetRepository.updateAll(ids, options);
this.communicationRepository.send(CommunicationEvent.ASSET_UPDATE, auth.user.id, ids);
this.communicationRepository.send(ClientEvent.ASSET_UPDATE, auth.user.id, ids);
}
async handleAssetDeletionCheck() {
@@ -478,7 +478,7 @@ export class AssetService {
}
await this.assetRepository.remove(asset);
this.communicationRepository.send(CommunicationEvent.ASSET_DELETE, asset.ownerId, id);
this.communicationRepository.send(ClientEvent.ASSET_DELETE, asset.ownerId, id);
// TODO refactor this to use cascades
if (asset.livePhotoVideoId) {
@@ -508,7 +508,7 @@ export class AssetService {
}
} else {
await this.assetRepository.softDeleteAll(ids);
this.communicationRepository.send(CommunicationEvent.ASSET_TRASH, auth.user.id, ids);
this.communicationRepository.send(ClientEvent.ASSET_TRASH, auth.user.id, ids);
}
}
@@ -521,7 +521,7 @@ export class AssetService {
for await (const assets of assetPagination) {
const ids = assets.map((a) => a.id);
await this.assetRepository.restoreAll(ids);
this.communicationRepository.send(CommunicationEvent.ASSET_RESTORE, auth.user.id, ids);
this.communicationRepository.send(ClientEvent.ASSET_RESTORE, auth.user.id, ids);
}
return;
}
@@ -540,7 +540,7 @@ export class AssetService {
const { ids } = dto;
await this.access.requirePermission(auth, Permission.ASSET_RESTORE, ids);
await this.assetRepository.restoreAll(ids);
this.communicationRepository.send(CommunicationEvent.ASSET_RESTORE, auth.user.id, ids);
this.communicationRepository.send(ClientEvent.ASSET_RESTORE, auth.user.id, ids);
}
async updateStackParent(auth: AuthDto, dto: UpdateStackParentDto): Promise<void> {
@@ -556,7 +556,7 @@ export class AssetService {
childIds.push(...(oldParent.stack?.map((a) => a.id) ?? []));
}
this.communicationRepository.send(CommunicationEvent.ASSET_UPDATE, auth.user.id, [...childIds, newParentId]);
this.communicationRepository.send(ClientEvent.ASSET_UPDATE, auth.user.id, [...childIds, newParentId]);
await this.assetRepository.updateAll(childIds, { stackParentId: newParentId });
// Remove ParentId of new parent if this was previously a child of some other asset
return this.assetRepository.updateAll([newParentId], { stackParentId: null });