mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 10:45:20 -04:00
Fix prettier errors
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
7960776bd1
commit
890e9c942b
4 changed files with 28 additions and 24 deletions
|
@ -17,21 +17,24 @@ import * as getRawBody from 'raw-body';
|
|||
*
|
||||
* Implementation inspired by https://stackoverflow.com/questions/52283713/how-do-i-pass-plain-text-as-my-request-body-using-nestjs
|
||||
*/
|
||||
export const MarkdownBody = createParamDecorator(async (_, context: ExecutionContext) => {
|
||||
// we have to check req.readable because of raw-body issue #57
|
||||
// https://github.com/stream-utils/raw-body/issues/57
|
||||
const req = context.switchToHttp().getRequest<import('express').Request>();
|
||||
// Here the Content-Type of the http request is checked to be text/markdown
|
||||
// because we dealing with markdown. Technically by now there can be any content which can be encoded.
|
||||
// There could be features in the software which do not work properly if the text can't be parsed as markdown.
|
||||
if (req.get('Content-Type') === 'text/markdown') {
|
||||
if (req.readable) {
|
||||
return (await getRawBody(req)).toString().trim();
|
||||
export const MarkdownBody = createParamDecorator(
|
||||
async (_, context: ExecutionContext) => {
|
||||
// we have to check req.readable because of raw-body issue #57
|
||||
// https://github.com/stream-utils/raw-body/issues/57
|
||||
const req = context.switchToHttp().getRequest<import('express').Request>();
|
||||
// Here the Content-Type of the http request is checked to be text/markdown
|
||||
// because we dealing with markdown. Technically by now there can be any content which can be encoded.
|
||||
// There could be features in the software which do not work properly if the text can't be parsed as markdown.
|
||||
if (req.get('Content-Type') === 'text/markdown') {
|
||||
if (req.readable) {
|
||||
return (await getRawBody(req)).toString().trim();
|
||||
} else {
|
||||
throw new InternalServerErrorException('Failed to parse request body!');
|
||||
}
|
||||
} else {
|
||||
throw new InternalServerErrorException('Failed to parse request body!');
|
||||
throw new BadRequestException(
|
||||
'Body Content-Type has to be text/markdown!',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw new BadRequestException('Body Content-Type has to be text/markdown!');
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue