From 0950e036b0bbc4921fbddbfe0177f300ee7349b4 Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Fri, 14 Apr 2023 18:07:44 +0200 Subject: [PATCH] refactor(s3-backend): use URL object to construct complete URL instead of string template Signed-off-by: Tilman Vatteroth --- backend/src/media/backends/s3-backend.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/src/media/backends/s3-backend.ts b/backend/src/media/backends/s3-backend.ts index 8f687fb3b..eca7bfc85 100644 --- a/backend/src/media/backends/s3-backend.ts +++ b/backend/src/media/backends/s3-backend.ts @@ -73,8 +73,10 @@ export class S3Backend implements MediaBackend { private getUrl(fileName: string): string { const url = new URL(this.config.endPoint); - const port = url.port !== '' ? `:${url.port}` : ''; - const bucket = this.config.bucket; - return `${url.protocol}//${url.hostname}${port}${url.pathname}${bucket}/${fileName}`; + if (!url.pathname.endsWith('/')) { + url.pathname += '/'; + } + url.pathname += `${this.config.bucket}/${fileName}`; + return url.toString(); } }