MediaController: Get parent note from HedgeDoc-Note header

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2020-10-17 16:44:00 +02:00
parent a877f57875
commit 273d9b2d19
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

View file

@ -1,5 +1,6 @@
import { import {
Controller, Controller,
Headers,
Post, Post,
UploadedFile, UploadedFile,
UseInterceptors, UseInterceptors,
@ -8,26 +9,32 @@ import { FileInterceptor } from '@nestjs/platform-express';
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';
import { NotesService } from '../../../notes/notes.service';
@Controller('media') @Controller('media')
export class MediaController { export class MediaController {
constructor( constructor(
private readonly logger: ConsoleLoggerService, private readonly logger: ConsoleLoggerService,
private mediaService: MediaService, private mediaService: MediaService,
private notesService: NotesService,
) { ) {
this.logger.setContext(MediaController.name); this.logger.setContext(MediaController.name);
} }
@Post('upload') @Post('upload')
@UseInterceptors(FileInterceptor('file')) @UseInterceptors(FileInterceptor('file'))
async uploadImage(@UploadedFile() file: MulterFile) { async uploadImage(
this.logger.debug('Recieved file: ' + file.originalname); @UploadedFile() file: MulterFile,
//TODO: Get user and note from request @Headers('HedgeDoc-Note') noteId: string,
const url = await this.mediaService.saveFile( ) {
file, //TODO: Get user from request
'hardcoded', const username = 'hardcoded';
'hardcoded', this.logger.debug(
`Recieved filename '${file.originalname}' for note '${noteId}' from user '${username}'`,
'uploadImage',
); );
const note = await this.notesService.getNoteByIdOrAlias(noteId);
const url = await this.mediaService.saveFile(file, username, note.id);
return { return {
link: url, link: url,
}; };