diff --git a/server/modules/storage/s3/common.js b/server/modules/storage/s3/common.js index 9471b2bf..bafcfbfe 100644 --- a/server/modules/storage/s3/common.js +++ b/server/modules/storage/s3/common.js @@ -34,10 +34,7 @@ module.exports = class S3CompatibleStorage { WIKI.logger.info(`(STORAGE/${this.storageName}) Initializing...`) const { accessKeyId, secretAccessKey, bucket } = this.config const s3Config = { - accessKeyId, - secretAccessKey, - params: { Bucket: bucket }, - apiVersions: '2006-03-01' + credentials: { accessKeyId, secretAccessKey } } if (!_.isNil(this.config.region)) { @@ -47,37 +44,37 @@ module.exports = class S3CompatibleStorage { s3Config.endpoint = this.config.endpoint } if (!_.isNil(this.config.sslEnabled)) { - s3Config.sslEnabled = this.config.sslEnabled + s3Config.tls = this.config.sslEnabled } if (!_.isNil(this.config.s3ForcePathStyle)) { - s3Config.s3ForcePathStyle = this.config.s3ForcePathStyle + s3Config.forcePathStyle = this.config.s3ForcePathStyle } if (!_.isNil(this.config.s3BucketEndpoint)) { - s3Config.s3BucketEndpoint = this.config.s3BucketEndpoint + s3Config.bucketEndpoint = this.config.s3BucketEndpoint } this.s3 = new S3(s3Config) this.bucketName = bucket // determine if a bucket exists and you have permission to access it - await this.s3.headBucket() + await this.s3.headBucket({ Bucket: this.bucketName }) WIKI.logger.info(`(STORAGE/${this.storageName}) Initialization completed.`) } async created(page) { WIKI.logger.info(`(STORAGE/${this.storageName}) Creating file ${page.path}...`) const filePath = getFilePath(page, 'path') - await this.s3.putObject({ Key: filePath, Body: page.injectMetadata() }) + await this.s3.putObject({ Bucket: this.bucketName, Key: filePath, Body: page.injectMetadata() }) } async updated(page) { WIKI.logger.info(`(STORAGE/${this.storageName}) Updating file ${page.path}...`) const filePath = getFilePath(page, 'path') - await this.s3.putObject({ Key: filePath, Body: page.injectMetadata() }) + await this.s3.putObject({ Bucket: this.bucketName, Key: filePath, Body: page.injectMetadata() }) } async deleted(page) { WIKI.logger.info(`(STORAGE/${this.storageName}) Deleting file ${page.path}...`) const filePath = getFilePath(page, 'path') - await this.s3.deleteObject({ Key: filePath }) + await this.s3.deleteObject({ Bucket: this.bucketName, Key: filePath }) } async renamed(page) { WIKI.logger.info(`(STORAGE/${this.storageName}) Renaming file ${page.path} to ${page.destinationPath}...`) @@ -91,8 +88,8 @@ module.exports = class S3CompatibleStorage { destinationFilePath = `${page.destinationLocaleCode}/${destinationFilePath}` } } - await this.s3.copyObject({ CopySource: `${this.bucketName}/${sourceFilePath}`, Key: destinationFilePath }) - await this.s3.deleteObject({ Key: sourceFilePath }) + await this.s3.copyObject({ Bucket: this.bucketName, CopySource: `${this.bucketName}/${sourceFilePath}`, Key: destinationFilePath }) + await this.s3.deleteObject({ Bucket: this.bucketName, Key: sourceFilePath }) } /** * ASSET UPLOAD @@ -101,7 +98,7 @@ module.exports = class S3CompatibleStorage { */ async assetUploaded (asset) { WIKI.logger.info(`(STORAGE/${this.storageName}) Creating new file ${asset.path}...`) - await this.s3.putObject({ Key: asset.path, Body: asset.data }) + await this.s3.putObject({ Bucket: this.bucketName, Key: asset.path, Body: asset.data }) } /** * ASSET DELETE @@ -110,7 +107,7 @@ module.exports = class S3CompatibleStorage { */ async assetDeleted (asset) { WIKI.logger.info(`(STORAGE/${this.storageName}) Deleting file ${asset.path}...`) - await this.s3.deleteObject({ Key: asset.path }) + await this.s3.deleteObject({ Bucket: this.bucketName, Key: asset.path }) } /** * ASSET RENAME @@ -119,8 +116,8 @@ 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: `${this.bucketName}/${asset.path}`, Key: asset.destinationPath }) - await this.s3.deleteObject({ Key: asset.path }) + await this.s3.copyObject({ Bucket: this.bucketName, CopySource: `${this.bucketName}/${asset.path}`, Key: asset.destinationPath }) + await this.s3.deleteObject({ Bucket: this.bucketName, Key: asset.path }) } async getLocalLocation () { @@ -141,7 +138,7 @@ module.exports = class S3CompatibleStorage { transform: async (page, enc, cb) => { const filePath = getFilePath(page, 'path') WIKI.logger.info(`(STORAGE/${this.storageName}) Adding page ${filePath}...`) - await this.s3.putObject({ Key: filePath, Body: pageHelper.injectPageMetadata(page) }) + await this.s3.putObject({ Bucket: this.bucketName, Key: filePath, Body: pageHelper.injectPageMetadata(page) }) cb() } }) @@ -157,7 +154,7 @@ module.exports = class S3CompatibleStorage { transform: async (asset, enc, cb) => { const filename = (asset.folderId && asset.folderId > 0) ? `${_.get(assetFolders, asset.folderId)}/${asset.filename}` : asset.filename WIKI.logger.info(`(STORAGE/${this.storageName}) Adding asset ${filename}...`) - await this.s3.putObject({ Key: filename, Body: asset.data }) + await this.s3.putObject({ Bucket: this.bucketName, Key: filename, Body: asset.data }) cb() } })