From dd41731382de2f9062aedddc4ea15aa222e6ac13 Mon Sep 17 00:00:00 2001 From: Caspar Neumann Date: Fri, 6 Oct 2023 12:42:18 +0200 Subject: [PATCH] refactor: only one return statement --- .../service/libraryStorage.service.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/apps/server/src/modules/h5p-editor/service/libraryStorage.service.ts b/apps/server/src/modules/h5p-editor/service/libraryStorage.service.ts index 71b64ae96b0..832aacaca08 100644 --- a/apps/server/src/modules/h5p-editor/service/libraryStorage.service.ts +++ b/apps/server/src/modules/h5p-editor/service/libraryStorage.service.ts @@ -426,29 +426,31 @@ export class LibraryStorage implements ILibraryStorage { */ public async getLibraryFile(ubername: string, file: string) { const libraryName = LibraryName.fromUberName(ubername); - this.checkFilename(file); + let returnValue: {}; if (file === 'library.json') { const metadata = await this.getMetadata(libraryName); const stringifiedMetadata = JSON.stringify(metadata); const readable = Readable.from(stringifiedMetadata); - return { + returnValue = { stream: readable, mimetype: 'application/json', size: stringifiedMetadata.length, }; - } - - const response = await this.s3Client.get(this.getS3Key(libraryName, file)); + } else{ + const response = await this.s3Client.get(this.getS3Key(libraryName, file)); + const mimetype = mime.lookup(file, 'application/octet-stream'); + + returnValue = { + stream: response.data, + mimetype, + size: response.contentLength, + }; - const mimetype = mime.lookup(file, 'application/octet-stream'); + } - return { - stream: response.data, - mimetype, - size: response.contentLength, - }; + return returnValue; } }