Skip to content

Commit

Permalink
Remove await from busboy on file
Browse files Browse the repository at this point in the history
  • Loading branch information
bischofmax committed Jan 15, 2024
1 parent 336ba02 commit e1e3a1c
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions apps/server/src/modules/files-storage/uc/files-storage.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,30 @@ export class FilesStorageUC {
private async uploadFileWithBusboy(userId: EntityId, params: FileRecordParams, req: Request): Promise<FileRecord> {
const promise = new Promise<FileRecord>((resolve, reject) => {
const bb = busboy({ headers: req.headers, defParamCharset: 'utf8' });
let promise2: Promise<FileRecord>;

// eslint-disable-next-line @typescript-eslint/no-misused-promises
bb.on('file', async (_name, file, info) => {
bb.on('file', (_name, file, info) => {
const fileDto = FileDtoBuilder.buildFromRequest(info, file);

try {
const result = await RequestContext.createAsync(this.em, async () => {
const record = await this.filesStorageService.uploadFile(userId, params, fileDto);
promise2 = RequestContext.createAsync(this.em, () => {
const record = this.filesStorageService.uploadFile(userId, params, fileDto);

return record;
return record;
});
});

bb.on('finish', () => {
promise2
.then((result) => {
resolve(result);
console.log('fileclose', result);
return result;
})
.catch((error) => {
this.logger.error({ message: 'could not upload file', error: error as Error });
req.unpipe(bb);
reject(error);
});
resolve(result);
} catch (error) {
this.logger.error({ message: 'could not upload file', error: error as Error });
req.unpipe(bb);
reject(error);
}
});

req.pipe(bb);
Expand Down

0 comments on commit e1e3a1c

Please sign in to comment.