From 004503034ed91d033b14ee2a16fdde4ce627b9eb Mon Sep 17 00:00:00 2001 From: Aditya Patadia Date: Sat, 28 Oct 2023 13:08:53 +0530 Subject: [PATCH] removed bucket path from non-path style config --- src/index.ts | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2676263..2f40952 100644 --- a/src/index.ts +++ b/src/index.ts @@ -63,21 +63,32 @@ class S3Storage extends StorageBase { if (!this.bucket) throw new Error('S3 bucket not specified') // Optional configurations - this.host = - process.env.GHOST_STORAGE_ADAPTER_S3_ASSET_HOST || - assetHost || - `https://s3${ + this.forcePathStyle = + Boolean(process.env.GHOST_STORAGE_ADAPTER_S3_FORCE_PATH_STYLE) || + Boolean(forcePathStyle) || + false + + let defaultHost; + + if(this.forcePathStyle) { + defaultHost = `https://s3${ this.region === 'us-east-1' ? '' : `-${this.region}` }.amazonaws.com/${this.bucket}` + } else { + defaultHost = `https://${this.bucket}.s3${ + this.region === 'us-east-1' ? '' : `-${this.region}` + }.amazonaws.com` + } + + this.host = + process.env.GHOST_STORAGE_ADAPTER_S3_ASSET_HOST || + assetHost || defaultHost + this.pathPrefix = stripLeadingSlash( process.env.GHOST_STORAGE_ADAPTER_S3_PATH_PREFIX || pathPrefix || '' ) this.endpoint = process.env.GHOST_STORAGE_ADAPTER_S3_ENDPOINT || endpoint || '' - this.forcePathStyle = - Boolean(process.env.GHOST_STORAGE_ADAPTER_S3_FORCE_PATH_STYLE) || - Boolean(forcePathStyle) || - false this.acl = (process.env.GHOST_STORAGE_ADAPTER_S3_ACL || acl || 'public-read') as ObjectCannedACL