mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
fix(media-controller): throw if no file was uploaded
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
9d8d5e8d55
commit
b311265762
2 changed files with 13 additions and 2 deletions
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import {
|
||||
BadRequestException,
|
||||
Controller,
|
||||
Delete,
|
||||
Param,
|
||||
|
@ -73,12 +74,15 @@ export class MediaController {
|
|||
500,
|
||||
)
|
||||
async uploadMedia(
|
||||
@UploadedFile() file: MulterFile,
|
||||
@UploadedFile() file: MulterFile | undefined,
|
||||
@RequestNote() note: Note,
|
||||
@RequestUser() user: User,
|
||||
): Promise<MediaUploadDto> {
|
||||
if (file === undefined) {
|
||||
throw new BadRequestException('Request does not contain a file');
|
||||
}
|
||||
this.logger.debug(
|
||||
`Recieved filename '${file.originalname}' for note '${note.id}' from user '${user.username}'`,
|
||||
`Received filename '${file.originalname}' for note '${note.id}' from user '${user.username}'`,
|
||||
'uploadMedia',
|
||||
);
|
||||
const upload = await this.mediaService.saveFile(file.buffer, user, note);
|
||||
|
|
|
@ -106,6 +106,13 @@ describe('Media', () => {
|
|||
.expect('Content-Type', /json/)
|
||||
.expect(500);
|
||||
});
|
||||
it('no media uploaded', async () => {
|
||||
await agent
|
||||
.post('/api/private/media')
|
||||
.set('HedgeDoc-Note', 'test_upload_media')
|
||||
.expect(400);
|
||||
await expect(fs.access(uploadPath)).rejects.toBeDefined();
|
||||
});
|
||||
afterEach(async () => {
|
||||
await ensureDeleted(uploadPath);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue