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