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() {
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.`)
}

@ -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()
}
})

Loading…
Cancel
Save