mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-23 07:12:01 +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 {
|
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,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue