chore: manually update config and remove .promise() calls

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

@ -22,32 +22,18 @@ module.exports = {
async init() { async init() {
WIKI.logger.info(`(SEARCH/AWS) Initializing...`) WIKI.logger.info(`(SEARCH/AWS) Initializing...`)
this.client = new CloudSearch({ 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: { credentials: {
accessKeyId: this.config.accessKeyId, accessKeyId: this.config.accessKeyId,
secretAccessKey: this.config.secretAccessKey secretAccessKey: this.config.secretAccessKey
}, },
region: this.config.region region: this.config.region
}) })
this.clientDomain = new CloudSearchDomain({ 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, endpoint: this.config.endpoint,
credentials: { credentials: {
accessKeyId: this.config.accessKeyId, accessKeyId: this.config.accessKeyId,
secretAccessKey: this.config.secretAccessKey secretAccessKey: this.config.secretAccessKey
}, },
region: this.config.region region: this.config.region
}) })
@ -57,7 +43,7 @@ module.exports = {
const schemes = await this.client.describeAnalysisSchemes({ const schemes = await this.client.describeAnalysisSchemes({
DomainName: this.config.domain, DomainName: this.config.domain,
AnalysisSchemeNames: ['default_anlscheme'] AnalysisSchemeNames: ['default_anlscheme']
}).promise() })
if (_.get(schemes, 'AnalysisSchemes', []).length < 1) { if (_.get(schemes, 'AnalysisSchemes', []).length < 1) {
WIKI.logger.info(`(SEARCH/AWS) Defining Analysis Scheme...`) WIKI.logger.info(`(SEARCH/AWS) Defining Analysis Scheme...`)
await this.client.defineAnalysisScheme({ await this.client.defineAnalysisScheme({
@ -66,14 +52,14 @@ module.exports = {
AnalysisSchemeLanguage: this.config.AnalysisSchemeLang, AnalysisSchemeLanguage: this.config.AnalysisSchemeLang,
AnalysisSchemeName: 'default_anlscheme' AnalysisSchemeName: 'default_anlscheme'
} }
}).promise() })
rebuildIndex = true rebuildIndex = true
} }
// -> Define Index Fields // -> Define Index Fields
const fields = await this.client.describeIndexFields({ const fields = await this.client.describeIndexFields({
DomainName: this.config.domain DomainName: this.config.domain
}).promise() })
if (_.get(fields, 'IndexFields', []).length < 1) { if (_.get(fields, 'IndexFields', []).length < 1) {
WIKI.logger.info(`(SEARCH/AWS) Defining Index Fields...`) WIKI.logger.info(`(SEARCH/AWS) Defining Index Fields...`)
await this.client.defineIndexField({ await this.client.defineIndexField({
@ -82,21 +68,21 @@ module.exports = {
IndexFieldName: 'id', IndexFieldName: 'id',
IndexFieldType: 'literal' IndexFieldType: 'literal'
} }
}).promise() })
await this.client.defineIndexField({ await this.client.defineIndexField({
DomainName: this.config.domain, DomainName: this.config.domain,
IndexField: { IndexField: {
IndexFieldName: 'path', IndexFieldName: 'path',
IndexFieldType: 'literal' IndexFieldType: 'literal'
} }
}).promise() })
await this.client.defineIndexField({ await this.client.defineIndexField({
DomainName: this.config.domain, DomainName: this.config.domain,
IndexField: { IndexField: {
IndexFieldName: 'locale', IndexFieldName: 'locale',
IndexFieldType: 'literal' IndexFieldType: 'literal'
} }
}).promise() })
await this.client.defineIndexField({ await this.client.defineIndexField({
DomainName: this.config.domain, DomainName: this.config.domain,
IndexField: { IndexField: {
@ -107,7 +93,7 @@ module.exports = {
AnalysisScheme: 'default_anlscheme' AnalysisScheme: 'default_anlscheme'
} }
} }
}).promise() })
await this.client.defineIndexField({ await this.client.defineIndexField({
DomainName: this.config.domain, DomainName: this.config.domain,
IndexField: { IndexField: {
@ -118,7 +104,7 @@ module.exports = {
AnalysisScheme: 'default_anlscheme' AnalysisScheme: 'default_anlscheme'
} }
} }
}).promise() })
await this.client.defineIndexField({ await this.client.defineIndexField({
DomainName: this.config.domain, DomainName: this.config.domain,
IndexField: { IndexField: {
@ -129,7 +115,7 @@ module.exports = {
AnalysisScheme: 'default_anlscheme' AnalysisScheme: 'default_anlscheme'
} }
} }
}).promise() })
rebuildIndex = true rebuildIndex = true
} }
@ -137,7 +123,7 @@ module.exports = {
const suggesters = await this.client.describeSuggesters({ const suggesters = await this.client.describeSuggesters({
DomainName: this.config.domain, DomainName: this.config.domain,
SuggesterNames: ['default_suggester'] SuggesterNames: ['default_suggester']
}).promise() })
if (_.get(suggesters, 'Suggesters', []).length < 1) { if (_.get(suggesters, 'Suggesters', []).length < 1) {
WIKI.logger.info(`(SEARCH/AWS) Defining Suggester...`) WIKI.logger.info(`(SEARCH/AWS) Defining Suggester...`)
await this.client.defineSuggester({ await this.client.defineSuggester({
@ -149,7 +135,7 @@ module.exports = {
FuzzyMatching: 'high' FuzzyMatching: 'high'
} }
} }
}).promise() })
rebuildIndex = true rebuildIndex = true
} }
@ -158,7 +144,7 @@ module.exports = {
WIKI.logger.info(`(SEARCH/AWS) Requesting Index Rebuild...`) WIKI.logger.info(`(SEARCH/AWS) Requesting Index Rebuild...`)
await this.client.indexDocuments({ await this.client.indexDocuments({
DomainName: this.config.domain DomainName: this.config.domain
}).promise() })
} }
WIKI.logger.info(`(SEARCH/AWS) Initialization completed.`) WIKI.logger.info(`(SEARCH/AWS) Initialization completed.`)
@ -176,13 +162,13 @@ module.exports = {
query: q, query: q,
partial: true, partial: true,
size: 50 size: 50
}).promise() })
if (results.hits.found < 5) { if (results.hits.found < 5) {
const suggestResults = await this.clientDomain.suggest({ const suggestResults = await this.clientDomain.suggest({
query: q, query: q,
suggester: 'default_suggester', suggester: 'default_suggester',
size: 5 size: 5
}).promise() })
suggestions = suggestResults.suggest.suggestions.map(s => s.suggestion) suggestions = suggestResults.suggest.suggestions.map(s => s.suggestion)
} }
return { return {
@ -222,7 +208,7 @@ module.exports = {
} }
} }
]) ])
}).promise() })
}, },
/** /**
* UPDATE * UPDATE
@ -245,7 +231,7 @@ module.exports = {
} }
} }
]) ])
}).promise() })
}, },
/** /**
* DELETE * DELETE
@ -261,7 +247,7 @@ module.exports = {
id: page.hash id: page.hash
} }
]) ])
}).promise() })
}, },
/** /**
* RENAME * RENAME
@ -277,7 +263,7 @@ module.exports = {
id: page.hash id: page.hash
} }
]) ])
}).promise() })
await this.clientDomain.uploadDocuments({ await this.clientDomain.uploadDocuments({
contentType: 'application/json', contentType: 'application/json',
documents: JSON.stringify([ documents: JSON.stringify([
@ -293,7 +279,7 @@ module.exports = {
} }
} }
]) ])
}).promise() })
}, },
/** /**
* REBUILD INDEX * REBUILD INDEX
@ -359,7 +345,7 @@ module.exports = {
content: WIKI.models.pages.cleanHTML(doc.render) content: WIKI.models.pages.cleanHTML(doc.render)
} }
}))) })))
}).promise() })
} catch (err) { } catch (err) {
WIKI.logger.warn('(SEARCH/AWS) Failed to send batch to AWS CloudSearch: ', 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...`) WIKI.logger.info(`(SEARCH/AWS) Requesting Index Rebuild...`)
await this.client.indexDocuments({ await this.client.indexDocuments({
DomainName: this.config.domain DomainName: this.config.domain
}).promise() })
WIKI.logger.info(`(SEARCH/AWS) Index rebuilt successfully.`) WIKI.logger.info(`(SEARCH/AWS) Index rebuilt successfully.`)
} }

@ -60,24 +60,24 @@ module.exports = class S3CompatibleStorage {
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().promise() await this.s3.headBucket()
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() }).promise() await this.s3.putObject({ 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() }).promise() await this.s3.putObject({ 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 }).promise() await this.s3.deleteObject({ 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 +91,8 @@ module.exports = class S3CompatibleStorage {
destinationFilePath = `${page.destinationLocaleCode}/${destinationFilePath}` destinationFilePath = `${page.destinationLocaleCode}/${destinationFilePath}`
} }
} }
await this.s3.copyObject({ CopySource: `${this.bucketName}/${sourceFilePath}`, Key: destinationFilePath }).promise() await this.s3.copyObject({ CopySource: `${this.bucketName}/${sourceFilePath}`, Key: destinationFilePath })
await this.s3.deleteObject({ Key: sourceFilePath }).promise() await this.s3.deleteObject({ Key: sourceFilePath })
} }
/** /**
* ASSET UPLOAD * ASSET UPLOAD
@ -101,7 +101,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 }).promise() await this.s3.putObject({ Key: asset.path, Body: asset.data })
} }
/** /**
* ASSET DELETE * ASSET DELETE
@ -110,7 +110,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 }).promise() await this.s3.deleteObject({ Key: asset.path })
} }
/** /**
* ASSET RENAME * ASSET RENAME
@ -119,8 +119,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 }).promise() await this.s3.copyObject({ CopySource: `${this.bucketName}/${asset.path}`, Key: asset.destinationPath })
await this.s3.deleteObject({ Key: asset.path }).promise() await this.s3.deleteObject({ Key: asset.path })
} }
async getLocalLocation () { async getLocalLocation () {
@ -141,7 +141,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) }).promise() await this.s3.putObject({ Key: filePath, Body: pageHelper.injectPageMetadata(page) })
cb() cb()
} }
}) })
@ -157,7 +157,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 }).promise() await this.s3.putObject({ Key: filename, Body: asset.data })
cb() cb()
} }
}) })

Loading…
Cancel
Save