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
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
|
BadRequestException,
|
||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
Param,
|
Param,
|
||||||
|
@ -73,12 +74,15 @@ export class MediaController {
|
||||||
500,
|
500,
|
||||||
)
|
)
|
||||||
async uploadMedia(
|
async uploadMedia(
|
||||||
@UploadedFile() file: MulterFile,
|
@UploadedFile() file: MulterFile | undefined,
|
||||||
@RequestNote() note: Note,
|
@RequestNote() note: Note,
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
): Promise<MediaUploadDto> {
|
): Promise<MediaUploadDto> {
|
||||||
|
if (file === undefined) {
|
||||||
|
throw new BadRequestException('Request does not contain a file');
|
||||||
|
}
|
||||||
this.logger.debug(
|
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',
|
'uploadMedia',
|
||||||
);
|
);
|
||||||
const upload = await this.mediaService.saveFile(file.buffer, user, note);
|
const upload = await this.mediaService.saveFile(file.buffer, user, note);
|
||||||
|
|
|
@ -106,6 +106,13 @@ describe('Media', () => {
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(500);
|
.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 () => {
|
afterEach(async () => {
|
||||||
await ensureDeleted(uploadPath);
|
await ensureDeleted(uploadPath);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue