refactor(api/public/media): return MediaUpload object instead of url

This ensures the POST /media API behaves in the same way as /me/media

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-01-29 19:06:38 +01:00
parent 8e31f3a393
commit 3f8e3b0589
2 changed files with 5 additions and 5 deletions

View file

@ -25,7 +25,7 @@ import {
import { TokenAuthGuard } from '../../../auth/token.strategy';
import { PermissionError } from '../../../errors/errors';
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
import { MediaUploadUrlDto } from '../../../media/media-upload-url.dto';
import { MediaUploadDto } from '../../../media/media-upload.dto';
import { MediaService } from '../../../media/media.service';
import { MulterFile } from '../../../media/multer-file.interface';
import { Note } from '../../../notes/note.entity';
@ -69,7 +69,7 @@ export class MediaController {
{
code: 201,
description: 'The file was uploaded successfully',
dto: MediaUploadUrlDto,
dto: MediaUploadDto,
},
400,
403,
@ -81,7 +81,7 @@ export class MediaController {
@RequestUser() user: User,
@UploadedFile() file: MulterFile,
@Headers('HedgeDoc-Note') noteId: string,
): Promise<MediaUploadUrlDto> {
): Promise<MediaUploadDto> {
// TODO: Move getting the Note object into a decorator
const note: Note = await this.noteService.getNoteByIdOrAlias(noteId);
this.logger.debug(
@ -89,7 +89,7 @@ export class MediaController {
'uploadMedia',
);
const upload = await this.mediaService.saveFile(file.buffer, user, note);
return this.mediaService.toMediaUploadUrlDto(upload.fileUrl);
return await this.mediaService.toMediaUploadDto(upload);
}
@Delete(':filename')

View file

@ -58,7 +58,7 @@ describe('Media', () => {
.set('HedgeDoc-Note', 'test_upload_media')
.expect('Content-Type', /json/)
.expect(201);
const path: string = uploadResponse.body.link;
const path: string = uploadResponse.body.url;
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
const downloadResponse = await request(testSetup.app.getHttpServer()).get(
path,