From 1a22f749bebcda65bcdefc25bf9519dd178a6a96 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Tue, 22 Sep 2020 18:31:20 +0200 Subject: [PATCH] NotesController: Get text from request body when creating a named note. Signed-off-by: David Mehren --- src/api/public/notes/notes.controller.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/api/public/notes/notes.controller.ts b/src/api/public/notes/notes.controller.ts index 1df997ab4..800e2e734 100644 --- a/src/api/public/notes/notes.controller.ts +++ b/src/api/public/notes/notes.controller.ts @@ -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')