diff --git a/api/src/attachment/controllers/attachment.controller.spec.ts b/api/src/attachment/controllers/attachment.controller.spec.ts index 4e23c2b7..5298dd1a 100644 --- a/api/src/attachment/controllers/attachment.controller.spec.ts +++ b/api/src/attachment/controllers/attachment.controller.spec.ts @@ -124,18 +124,20 @@ describe('AttachmentController', () => { }, { context: 'block_attachment' }, ); - expect(attachmentService.create).toHaveBeenCalledWith({ - size: attachmentFile.size, - type: attachmentFile.mimetype, - name: attachmentFile.filename, - location: `/${attachmentFile.filename}`, - ownerType: 'User', - owner: id, - context: 'block_attachment', - }); + // const [name, ext] = attachmentFile.filename.split('.'); + expect(attachmentService.create).toHaveBeenCalledWith( + expect.objectContaining({ + size: attachmentFile.size, + type: attachmentFile.mimetype, + name: attachmentFile.filename, + ownerType: 'User', + owner: id, + context: 'block_attachment', + }), + ); expect(result).toEqualPayload( [{ ...attachment, ownerType: 'User', owner: id }], - [...IGNORED_TEST_FIELDS, 'url'], + [...IGNORED_TEST_FIELDS, 'url', 'location'], ); }); }); diff --git a/api/src/attachment/controllers/attachment.controller.ts b/api/src/attachment/controllers/attachment.controller.ts index 28ac7db7..ed83660c 100644 --- a/api/src/attachment/controllers/attachment.controller.ts +++ b/api/src/attachment/controllers/attachment.controller.ts @@ -45,7 +45,6 @@ import { import { AttachmentGuard } from '../guards/attachment-ability.guard'; import { Attachment } from '../schemas/attachment.schema'; import { AttachmentService } from '../services/attachment.service'; -import { generateUniqueFilename } from '../utilities'; @UseInterceptors(CsrfInterceptor) @Controller('attachment') @@ -124,12 +123,7 @@ export class AttachmentController extends BaseController { if (config.parameters.storageMode === 'memory') { return memoryStorage(); } else { - return diskStorage({ - destination: config.parameters.uploadDir, - filename: (_req, file, cb) => { - cb(null, generateUniqueFilename(file.originalname)); - }, - }); + return diskStorage({}); } })(), }), @@ -152,14 +146,13 @@ export class AttachmentController extends BaseController { const attachments = []; for (const file of files.file) { - const attachment = await this.attachmentService.store(file.buffer, { + const attachment = await this.attachmentService.store(file, { name: file.originalname, size: file.size, type: file.mimetype, context, owner: userId, ownerType: 'User', - location: `/${file.filename}`, }); attachments.push(attachment); }