mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-30 23:12:22 +00:00
NotesController: Get text from request body when creating a named note.
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
9da1a88e74
commit
1a22f749be
1 changed files with 13 additions and 3 deletions
|
@ -52,11 +52,21 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@Post(':noteAlias')
|
||||
createNamedNote(
|
||||
async createNamedNote(
|
||||
@Param('noteAlias') noteAlias: string,
|
||||
@Body() noteContent: string,
|
||||
@Req() req: Request,
|
||||
) {
|
||||
return this.noteService.createNote(noteContent, noteAlias);
|
||||
// we have to check req.readable because of raw-body issue #57
|
||||
// https://github.com/stream-utils/raw-body/issues/57
|
||||
if (req.readable) {
|
||||
let bodyText: string = await getRawBody(req, 'utf-8');
|
||||
bodyText = bodyText.trim();
|
||||
this.logger.debug('Got raw markdown:\n' + bodyText);
|
||||
return this.noteService.createNote(bodyText, noteAlias);
|
||||
} else {
|
||||
// TODO: Better error message
|
||||
throw new BadRequestException('Invalid body');
|
||||
}
|
||||
}
|
||||
|
||||
@Delete(':noteIdOrAlias')
|
||||
|
|
Loading…
Reference in a new issue