mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-27 12:08:02 -05: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 {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
Controller,
|
Controller,
|
||||||
|
Delete,
|
||||||
Headers,
|
Headers,
|
||||||
|
NotFoundException,
|
||||||
|
Param,
|
||||||
Post,
|
Post,
|
||||||
|
UnauthorizedException,
|
||||||
UploadedFile,
|
UploadedFile,
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { FileInterceptor } from '@nestjs/platform-express';
|
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 { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||||
import { MediaService } from '../../../media/media.service';
|
import { MediaService } from '../../../media/media.service';
|
||||||
import { MulterFile } from '../../../media/multer-file.interface';
|
import { MulterFile } from '../../../media/multer-file.interface';
|
||||||
|
@ -25,7 +33,7 @@ export class MediaController {
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@UseInterceptors(FileInterceptor('file'))
|
@UseInterceptors(FileInterceptor('file'))
|
||||||
async uploadImage(
|
async uploadMedia(
|
||||||
@UploadedFile() file: MulterFile,
|
@UploadedFile() file: MulterFile,
|
||||||
@Headers('HedgeDoc-Note') noteId: string,
|
@Headers('HedgeDoc-Note') noteId: string,
|
||||||
) {
|
) {
|
||||||
|
@ -47,4 +55,21 @@ export class MediaController {
|
||||||
throw e;
|
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