mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-28 14:51:29 +00:00
MediaController: Add DELETE /{filename}
route
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
9e7e15a20a
commit
3686685f08
1 changed files with 27 additions and 2 deletions
|
@ -1,13 +1,21 @@
|
|||
import {
|
||||
BadRequestException,
|
||||
Controller,
|
||||
Delete,
|
||||
Headers,
|
||||
NotFoundException,
|
||||
Param,
|
||||
Post,
|
||||
UnauthorizedException,
|
||||
UploadedFile,
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { ClientError, NotInDBError } from '../../../errors/errors';
|
||||
import {
|
||||
ClientError,
|
||||
NotInDBError,
|
||||
PermissionError,
|
||||
} from '../../../errors/errors';
|
||||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||
import { MediaService } from '../../../media/media.service';
|
||||
import { MulterFile } from '../../../media/multer-file.interface';
|
||||
|
@ -25,7 +33,7 @@ export class MediaController {
|
|||
|
||||
@Post()
|
||||
@UseInterceptors(FileInterceptor('file'))
|
||||
async uploadImage(
|
||||
async uploadMedia(
|
||||
@UploadedFile() file: MulterFile,
|
||||
@Headers('HedgeDoc-Note') noteId: string,
|
||||
) {
|
||||
|
@ -47,4 +55,21 @@ export class MediaController {
|
|||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Delete(':filename')
|
||||
async deleteMedia(@Param('filename') filename: string) {
|
||||
//TODO: Get user from request
|
||||
const username = 'hardcoded';
|
||||
try {
|
||||
await this.mediaService.deleteFile(filename, username);
|
||||
} catch (e) {
|
||||
if (e instanceof PermissionError) {
|
||||
throw new UnauthorizedException(e.message);
|
||||
}
|
||||
if (e instanceof NotInDBError) {
|
||||
throw new NotFoundException(e.message);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue