Skip to content

Commit ddbc471

Browse files
committed
Add event for after file (version) upload
1 parent f464fc3 commit ddbc471

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { File } from '../dto';
2+
3+
/**
4+
* Emitted as the last step of the file upload process.
5+
* Feel free to throw to abort mutation.
6+
*/
7+
export class AfterFileUploadEvent {
8+
constructor(readonly file: File) {}
9+
}

src/components/file/file.service.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { Connection } from 'cypher-query-builder';
88
import { intersection } from 'lodash';
99
import { Duration } from 'luxon';
1010
import { Readable } from 'stream';
11-
import { withAddedPath } from '~/common/url.util';
1211
import {
1312
DuplicateException,
1413
DurationIn,
@@ -19,8 +18,9 @@ import {
1918
ServerException,
2019
Session,
2120
UnauthorizedException,
22-
} from '../../common';
23-
import { ConfigService, ILogger, Logger } from '../../core';
21+
} from '~/common';
22+
import { withAddedPath } from '~/common/url.util';
23+
import { ConfigService, IEventBus, ILogger, Logger } from '~/core';
2424
import { FileBucket } from './bucket';
2525
import {
2626
CreateDefinedFileVersionInput,
@@ -41,6 +41,7 @@ import {
4141
RenameFileInput,
4242
RequestUploadOutput,
4343
} from './dto';
44+
import { AfterFileUploadEvent } from './events/after-file-upload.event';
4445
import { FileUrlController as FileUrl } from './file-url.controller';
4546
import { FileRepository } from './file.repository';
4647
import { MediaService } from './media/media.service';
@@ -53,6 +54,7 @@ export class FileService {
5354
private readonly db: Connection,
5455
private readonly config: ConfigService,
5556
private readonly mediaService: MediaService,
57+
private readonly eventBus: IEventBus,
5658
@Logger('file:service') private readonly logger: ILogger,
5759
) {}
5860

@@ -361,7 +363,11 @@ export class FileService {
361363
// Change the file's name to match the latest version name
362364
await this.rename({ id: fileId, name }, session);
363365

364-
return await this.getFile(fileId, session);
366+
const file = await this.getFile(fileId, session);
367+
368+
await this.eventBus.publish(new AfterFileUploadEvent(file));
369+
370+
return file;
365371
}
366372

367373
private async validateParentNode(

0 commit comments

Comments
 (0)