mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 09:46:30 -05: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
cccd52d1b0
commit
1abb472621
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