From 9682b05a00c97b9203463cab9b0bf4b16e770320 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Mon, 19 Feb 2024 12:34:13 -0800 Subject: [PATCH] chore: manually update config and remove .promise() calls --- server/modules/search/aws/engine.js | 56 +++++++++++------------------ server/modules/storage/s3/common.js | 24 ++++++------- 2 files changed, 33 insertions(+), 47 deletions(-) diff --git a/server/modules/search/aws/engine.js b/server/modules/search/aws/engine.js index f5c110be..d81cfa23 100644 --- a/server/modules/search/aws/engine.js +++ b/server/modules/search/aws/engine.js @@ -22,32 +22,18 @@ module.exports = { async init() { WIKI.logger.info(`(SEARCH/AWS) Initializing...`) this.client = new CloudSearch({ - // The key apiVersion is no longer supported in v3, and can be removed. - // @deprecated The client uses the "latest" apiVersion. - apiVersion: '2013-01-01', - credentials: { accessKeyId: this.config.accessKeyId, secretAccessKey: this.config.secretAccessKey }, - region: this.config.region }) this.clientDomain = new CloudSearchDomain({ - // The key apiVersion is no longer supported in v3, and can be removed. - // @deprecated The client uses the "latest" apiVersion. - apiVersion: '2013-01-01', - - // The transformation for endpoint is not implemented. - // Refer to UPGRADING.md on aws-sdk-js-v3 for changes needed. - // Please create/upvote feature request on aws-sdk-js-codemod for endpoint. endpoint: this.config.endpoint, - credentials: { accessKeyId: this.config.accessKeyId, secretAccessKey: this.config.secretAccessKey }, - region: this.config.region }) @@ -57,7 +43,7 @@ module.exports = { const schemes = await this.client.describeAnalysisSchemes({ DomainName: this.config.domain, AnalysisSchemeNames: ['default_anlscheme'] - }).promise() + }) if (_.get(schemes, 'AnalysisSchemes', []).length < 1) { WIKI.logger.info(`(SEARCH/AWS) Defining Analysis Scheme...`) await this.client.defineAnalysisScheme({ @@ -66,14 +52,14 @@ module.exports = { AnalysisSchemeLanguage: this.config.AnalysisSchemeLang, AnalysisSchemeName: 'default_anlscheme' } - }).promise() + }) rebuildIndex = true } // -> Define Index Fields const fields = await this.client.describeIndexFields({ DomainName: this.config.domain - }).promise() + }) if (_.get(fields, 'IndexFields', []).length < 1) { WIKI.logger.info(`(SEARCH/AWS) Defining Index Fields...`) await this.client.defineIndexField({ @@ -82,21 +68,21 @@ module.exports = { IndexFieldName: 'id', IndexFieldType: 'literal' } - }).promise() + }) await this.client.defineIndexField({ DomainName: this.config.domain, IndexField: { IndexFieldName: 'path', IndexFieldType: 'literal' } - }).promise() + }) await this.client.defineIndexField({ DomainName: this.config.domain, IndexField: { IndexFieldName: 'locale', IndexFieldType: 'literal' } - }).promise() + }) await this.client.defineIndexField({ DomainName: this.config.domain, IndexField: { @@ -107,7 +93,7 @@ module.exports = { AnalysisScheme: 'default_anlscheme' } } - }).promise() + }) await this.client.defineIndexField({ DomainName: this.config.domain, IndexField: { @@ -118,7 +104,7 @@ module.exports = { AnalysisScheme: 'default_anlscheme' } } - }).promise() + }) await this.client.defineIndexField({ DomainName: this.config.domain, IndexField: { @@ -129,7 +115,7 @@ module.exports = { AnalysisScheme: 'default_anlscheme' } } - }).promise() + }) rebuildIndex = true } @@ -137,7 +123,7 @@ module.exports = { const suggesters = await this.client.describeSuggesters({ DomainName: this.config.domain, SuggesterNames: ['default_suggester'] - }).promise() + }) if (_.get(suggesters, 'Suggesters', []).length < 1) { WIKI.logger.info(`(SEARCH/AWS) Defining Suggester...`) await this.client.defineSuggester({ @@ -149,7 +135,7 @@ module.exports = { FuzzyMatching: 'high' } } - }).promise() + }) rebuildIndex = true } @@ -158,7 +144,7 @@ module.exports = { WIKI.logger.info(`(SEARCH/AWS) Requesting Index Rebuild...`) await this.client.indexDocuments({ DomainName: this.config.domain - }).promise() + }) } WIKI.logger.info(`(SEARCH/AWS) Initialization completed.`) @@ -176,13 +162,13 @@ module.exports = { query: q, partial: true, size: 50 - }).promise() + }) if (results.hits.found < 5) { const suggestResults = await this.clientDomain.suggest({ query: q, suggester: 'default_suggester', size: 5 - }).promise() + }) suggestions = suggestResults.suggest.suggestions.map(s => s.suggestion) } return { @@ -222,7 +208,7 @@ module.exports = { } } ]) - }).promise() + }) }, /** * UPDATE @@ -245,7 +231,7 @@ module.exports = { } } ]) - }).promise() + }) }, /** * DELETE @@ -261,7 +247,7 @@ module.exports = { id: page.hash } ]) - }).promise() + }) }, /** * RENAME @@ -277,7 +263,7 @@ module.exports = { id: page.hash } ]) - }).promise() + }) await this.clientDomain.uploadDocuments({ contentType: 'application/json', documents: JSON.stringify([ @@ -293,7 +279,7 @@ module.exports = { } } ]) - }).promise() + }) }, /** * REBUILD INDEX @@ -359,7 +345,7 @@ module.exports = { content: WIKI.models.pages.cleanHTML(doc.render) } }))) - }).promise() + }) } catch (err) { WIKI.logger.warn('(SEARCH/AWS) Failed to send batch to AWS CloudSearch: ', err) } @@ -382,7 +368,7 @@ module.exports = { WIKI.logger.info(`(SEARCH/AWS) Requesting Index Rebuild...`) await this.client.indexDocuments({ DomainName: this.config.domain - }).promise() + }) WIKI.logger.info(`(SEARCH/AWS) Index rebuilt successfully.`) } diff --git a/server/modules/storage/s3/common.js b/server/modules/storage/s3/common.js index 0b2447a2..9471b2bf 100644 --- a/server/modules/storage/s3/common.js +++ b/server/modules/storage/s3/common.js @@ -60,24 +60,24 @@ module.exports = class S3CompatibleStorage { this.bucketName = bucket // determine if a bucket exists and you have permission to access it - await this.s3.headBucket().promise() + await this.s3.headBucket() 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() }).promise() + await this.s3.putObject({ 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() }).promise() + await this.s3.putObject({ 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 }).promise() + await this.s3.deleteObject({ Key: filePath }) } async renamed(page) { WIKI.logger.info(`(STORAGE/${this.storageName}) Renaming file ${page.path} to ${page.destinationPath}...`) @@ -91,8 +91,8 @@ 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() + await this.s3.copyObject({ CopySource: `${this.bucketName}/${sourceFilePath}`, Key: destinationFilePath }) + await this.s3.deleteObject({ Key: sourceFilePath }) } /** * ASSET UPLOAD @@ -101,7 +101,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 }).promise() + await this.s3.putObject({ Key: asset.path, Body: asset.data }) } /** * ASSET DELETE @@ -110,7 +110,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 }).promise() + await this.s3.deleteObject({ Key: asset.path }) } /** * ASSET RENAME @@ -119,8 +119,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 }).promise() - await this.s3.deleteObject({ Key: asset.path }).promise() + await this.s3.copyObject({ CopySource: `${this.bucketName}/${asset.path}`, Key: asset.destinationPath }) + await this.s3.deleteObject({ Key: asset.path }) } async getLocalLocation () { @@ -141,7 +141,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) }).promise() + await this.s3.putObject({ Key: filePath, Body: pageHelper.injectPageMetadata(page) }) cb() } }) @@ -157,7 +157,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 }).promise() + await this.s3.putObject({ Key: filename, Body: asset.data }) cb() } })