mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-22 11:15:23 -04:00
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:
parent
8e31f3a393
commit
3f8e3b0589
2 changed files with 5 additions and 5 deletions
|
@ -25,7 +25,7 @@ import {
|
||||||
import { TokenAuthGuard } from '../../../auth/token.strategy';
|
import { TokenAuthGuard } from '../../../auth/token.strategy';
|
||||||
import { PermissionError } from '../../../errors/errors';
|
import { PermissionError } from '../../../errors/errors';
|
||||||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
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 { MediaService } from '../../../media/media.service';
|
||||||
import { MulterFile } from '../../../media/multer-file.interface';
|
import { MulterFile } from '../../../media/multer-file.interface';
|
||||||
import { Note } from '../../../notes/note.entity';
|
import { Note } from '../../../notes/note.entity';
|
||||||
|
@ -69,7 +69,7 @@ export class MediaController {
|
||||||
{
|
{
|
||||||
code: 201,
|
code: 201,
|
||||||
description: 'The file was uploaded successfully',
|
description: 'The file was uploaded successfully',
|
||||||
dto: MediaUploadUrlDto,
|
dto: MediaUploadDto,
|
||||||
},
|
},
|
||||||
400,
|
400,
|
||||||
403,
|
403,
|
||||||
|
@ -81,7 +81,7 @@ export class MediaController {
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
@UploadedFile() file: MulterFile,
|
@UploadedFile() file: MulterFile,
|
||||||
@Headers('HedgeDoc-Note') noteId: string,
|
@Headers('HedgeDoc-Note') noteId: string,
|
||||||
): Promise<MediaUploadUrlDto> {
|
): Promise<MediaUploadDto> {
|
||||||
// TODO: Move getting the Note object into a decorator
|
// TODO: Move getting the Note object into a decorator
|
||||||
const note: Note = await this.noteService.getNoteByIdOrAlias(noteId);
|
const note: Note = await this.noteService.getNoteByIdOrAlias(noteId);
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
|
@ -89,7 +89,7 @@ export class MediaController {
|
||||||
'uploadMedia',
|
'uploadMedia',
|
||||||
);
|
);
|
||||||
const upload = await this.mediaService.saveFile(file.buffer, user, note);
|
const upload = await this.mediaService.saveFile(file.buffer, user, note);
|
||||||
return this.mediaService.toMediaUploadUrlDto(upload.fileUrl);
|
return await this.mediaService.toMediaUploadDto(upload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':filename')
|
@Delete(':filename')
|
||||||
|
|
|
@ -58,7 +58,7 @@ describe('Media', () => {
|
||||||
.set('HedgeDoc-Note', 'test_upload_media')
|
.set('HedgeDoc-Note', 'test_upload_media')
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(201);
|
.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 testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
||||||
const downloadResponse = await request(testSetup.app.getHttpServer()).get(
|
const downloadResponse = await request(testSetup.app.getHttpServer()).get(
|
||||||
path,
|
path,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue