fix(server/workflow): add trigger for external libraries AssetCreate (#29597)

This commit is contained in:
Andreas Heinz 2026-07-15 19:30:33 +02:00 committed by GitHub
parent 2237078bd5
commit e7f773197f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 2 deletions

View File

@ -42,7 +42,7 @@ type EventMap = {
AlbumInvite: [{ id: string; userId: string; senderName: string }];
// asset events
AssetCreate: [{ asset: Asset; file: UploadFile }];
AssetCreate: [{ asset: Pick<Asset, 'id' | 'ownerId'>; file?: UploadFile }];
AssetTag: [{ assetId: string }];
AssetUntag: [{ assetId: string }];
AssetHide: [{ assetId: string; userId: string }];

View File

@ -576,6 +576,10 @@ describe(LibraryService.name, () => {
}),
]);
expect(mocks.event.emit).toHaveBeenCalledWith('AssetCreate', {
asset: { id: asset.id, ownerId: library.ownerId },
});
expect(mocks.job.queueAll).toHaveBeenCalledWith([
{
name: JobName.SidecarCheck,

View File

@ -275,6 +275,12 @@ export class LibraryService extends BaseService {
this.logger.log(`Imported ${assetIds.length} ${progressMessage} file(s) into library ${job.libraryId}`);
await Promise.all(
assetIds.map((assetId) =>
this.eventRepository.emit('AssetCreate', { asset: { id: assetId, ownerId: library.ownerId } }),
),
);
await this.queuePostSyncJobs(assetIds);
return JobStatus.Success;

View File

@ -239,7 +239,9 @@ export class UserService extends BaseService {
@OnEvent({ name: 'AssetCreate' })
async onAssetCreate({ asset, file }: ArgOf<'AssetCreate'>) {
await this.userRepository.updateUsage(asset.ownerId, file.size);
if (file) {
await this.userRepository.updateUsage(asset.ownerId, file.size);
}
}
@OnJob({ name: JobName.UserSyncUsage, queue: QueueName.BackgroundTask })