chore: update configuration for JS SDK v3 S3 client

pull/7008/head
Kamat, Trivikram 2 years ago
parent 9682b05a00
commit b9fac491ba

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

Loading…
Cancel
Save