From 2016874a3dd5b7e7ee79612f57167ca669eb3c2d Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Fri, 14 Apr 2023 10:43:45 +0200 Subject: [PATCH] fix(s3-backend): let minio lib handle the port fallback Signed-off-by: Tilman Vatteroth --- backend/src/media/backends/s3-backend.ts | 32 +++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/backend/src/media/backends/s3-backend.ts b/backend/src/media/backends/s3-backend.ts index 1cc464bf3..40db05628 100644 --- a/backend/src/media/backends/s3-backend.ts +++ b/backend/src/media/backends/s3-backend.ts @@ -25,22 +25,24 @@ export class S3Backend implements MediaBackend { private mediaConfig: MediaConfig, ) { this.logger.setContext(S3Backend.name); - if (mediaConfig.backend.use === BackendType.S3) { - this.config = mediaConfig.backend.s3; - const url = new URL(this.config.endPoint); - const secure = url.protocol === 'https:'; // url.protocol contains a trailing ':' - let port = parseInt(url.port); - if (isNaN(port)) { - port = secure ? 443 : 80; - } - this.client = new Client({ - endPoint: url.hostname, - port: port, - useSSL: secure, - accessKey: this.config.accessKeyId, - secretKey: this.config.secretAccessKey, - }); + if (mediaConfig.backend.use !== BackendType.S3) { + return; } + this.config = mediaConfig.backend.s3; + const url = new URL(this.config.endPoint); + const isSecure = url.protocol === 'https:'; + this.client = new Client({ + endPoint: url.hostname, + port: this.determinePort(url), + useSSL: isSecure, + accessKey: this.config.accessKeyId, + secretKey: this.config.secretAccessKey, + }); + } + + private determinePort(url: URL): number | undefined { + const port = parseInt(url.port); + return isNaN(port) ? undefined : port; } async saveFile(