mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-23 02:52:17 +00:00
MediaController: Get parent note from HedgeDoc-Note
header
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
a877f57875
commit
273d9b2d19
1 changed files with 14 additions and 7 deletions
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue