From d76d83a761a5f984a8080d09eef2893c52ee147e Mon Sep 17 00:00:00 2001 From: MaXeraph Date: Mon, 22 Mar 2021 22:15:02 -0400 Subject: [PATCH 1/4] Fix copyObject usage: supply bucket name --- server/modules/storage/s3/common.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/modules/storage/s3/common.js b/server/modules/storage/s3/common.js index c34e245109..f987af6f5e 100644 --- a/server/modules/storage/s3/common.js +++ b/server/modules/storage/s3/common.js @@ -22,6 +22,7 @@ const getFilePath = (page, pathKey) => { module.exports = class S3CompatibleStorage { constructor(storageName) { this.storageName = storageName + this.bucketName; } async activated() { // not used @@ -32,6 +33,7 @@ module.exports = class S3CompatibleStorage { async init() { WIKI.logger.info(`(STORAGE/${this.storageName}) Initializing...`) const { accessKeyId, secretAccessKey, bucket } = this.config + this.bucketName = bucket; const s3Config = { accessKeyId, secretAccessKey, @@ -89,7 +91,8 @@ module.exports = class S3CompatibleStorage { destinationFilePath = `${page.destinationLocaleCode}/${destinationFilePath}` } } - await this.s3.copyObject({ CopySource: sourceFilePath, Key: destinationFilePath }).promise() + + await this.s3.copyObject({ CopySource: `${this.bucketName}/${sourceFilePath}`, Key: destinationFilePath }).promise() await this.s3.deleteObject({ Key: sourceFilePath }).promise() } /** @@ -117,7 +120,7 @@ module.exports = class S3CompatibleStorage { */ async assetRenamed (asset) { WIKI.logger.info(`(STORAGE/${this.storageName}) Renaming file from ${asset.path} to ${asset.destinationPath}...`) - await this.s3.copyObject({ CopySource: asset.path, Key: asset.destinationPath }).promise() + await this.s3.copyObject({ CopySource: `${this.bucketName}/${asset.path}`, Key: asset.destinationPath }).promise() await this.s3.deleteObject({ Key: asset.path }).promise() } async getLocalLocation () { From b8b3073e7bd8e697c62d343ca0b2936fcf8f6a4a Mon Sep 17 00:00:00 2001 From: MaXeraph Date: Tue, 23 Mar 2021 00:03:29 -0400 Subject: [PATCH 2/4] No semicolon --- server/modules/storage/s3/common.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/modules/storage/s3/common.js b/server/modules/storage/s3/common.js index f987af6f5e..4492af0a37 100644 --- a/server/modules/storage/s3/common.js +++ b/server/modules/storage/s3/common.js @@ -22,7 +22,7 @@ const getFilePath = (page, pathKey) => { module.exports = class S3CompatibleStorage { constructor(storageName) { this.storageName = storageName - this.bucketName; + this.bucketName } async activated() { // not used @@ -33,7 +33,6 @@ module.exports = class S3CompatibleStorage { async init() { WIKI.logger.info(`(STORAGE/${this.storageName}) Initializing...`) const { accessKeyId, secretAccessKey, bucket } = this.config - this.bucketName = bucket; const s3Config = { accessKeyId, secretAccessKey, @@ -58,6 +57,7 @@ module.exports = class S3CompatibleStorage { } this.s3 = new S3(s3Config) + this.bucketName = bucket // determine if a bucket exists and you have permission to access it await this.s3.headBucket().promise() From 6210b841495daa796b751b51d024892ea20228c3 Mon Sep 17 00:00:00 2001 From: MaXeraph Date: Tue, 23 Mar 2021 11:05:25 -0400 Subject: [PATCH 3/4] Assign empty string on initialization --- server/modules/storage/s3/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/modules/storage/s3/common.js b/server/modules/storage/s3/common.js index 4492af0a37..4a98a0f7e1 100644 --- a/server/modules/storage/s3/common.js +++ b/server/modules/storage/s3/common.js @@ -22,7 +22,7 @@ const getFilePath = (page, pathKey) => { module.exports = class S3CompatibleStorage { constructor(storageName) { this.storageName = storageName - this.bucketName + this.bucketName = "" } async activated() { // not used From d52196a7bf0c4175eb8527d09ee847ac7a0bf67f Mon Sep 17 00:00:00 2001 From: MaXeraph Date: Tue, 23 Mar 2021 11:08:03 -0400 Subject: [PATCH 4/4] Remove empty line --- server/modules/storage/s3/common.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/modules/storage/s3/common.js b/server/modules/storage/s3/common.js index 4a98a0f7e1..fa1bc5dcda 100644 --- a/server/modules/storage/s3/common.js +++ b/server/modules/storage/s3/common.js @@ -91,7 +91,6 @@ module.exports = class S3CompatibleStorage { destinationFilePath = `${page.destinationLocaleCode}/${destinationFilePath}` } } - await this.s3.copyObject({ CopySource: `${this.bucketName}/${sourceFilePath}`, Key: destinationFilePath }).promise() await this.s3.deleteObject({ Key: sourceFilePath }).promise() }