-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding eslint * Linter remediation * refactoring with async/await * Adding more explicit types that are not 'any'
- Loading branch information
Showing
18 changed files
with
8,775 additions
and
3,165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = { | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es2021": true | ||
}, | ||
"extends": "standard-with-typescript", | ||
"overrides": [ | ||
{ | ||
"env": { | ||
"node": true | ||
}, | ||
"files": [ | ||
".eslintrc.{js,cjs}" | ||
], | ||
"parserOptions": { | ||
"sourceType": "script" | ||
} | ||
} | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": "latest" | ||
}, | ||
"ignorePatterns": [ | ||
".eslintrc.js" | ||
], | ||
"rules": { | ||
"semi": "off", | ||
"@typescript-eslint/semi": "warn" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,7 @@ out | |
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
distProd | ||
|
||
# Gatsby files | ||
.cache/ | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,62 @@ | ||
import * as BucketUtils from './bucketUtils'; | ||
import * as Utils from './utils'; | ||
import * as PollyUtils from './pollyUtils'; | ||
import * as ComprehendUtils from './comprehendUtils'; | ||
import { StartSpeechSynthesisTaskOutput } from '@aws-sdk/client-polly'; | ||
import { log4TSProvider } from './config/LogConfig'; | ||
import * as BucketUtils from './bucketUtils' | ||
import * as Utils from './utils' | ||
import * as PollyUtils from './pollyUtils' | ||
import * as ComprehendUtils from './comprehendUtils' | ||
import { type StartSpeechSynthesisTaskCommandOutput } from '@aws-sdk/client-polly' | ||
import { type DeleteObjectCommandOutput, type GetObjectCommandOutput, type PutObjectCommandOutput } from '@aws-sdk/client-s3' | ||
import { type DetectKeyPhrasesCommandOutput } from '@aws-sdk/client-comprehend' | ||
import { type S3Event } from 'aws-lambda' | ||
|
||
const log = log4TSProvider.getLogger('App'); | ||
import { log4TSProvider } from './config/LogConfig' | ||
|
||
export function handler(event: any) { | ||
log.info('incoming event', JSON.stringify(event)); | ||
const rec: any = event.Records[0]; | ||
const fileName: string = rec.s3.object.key; | ||
log.info('processing file', fileName); | ||
const log = log4TSProvider.getLogger('App') | ||
|
||
let text: string | undefined; | ||
let createDetailsMp3: any; | ||
let createDetailsCsv: any; | ||
export async function handler (event: S3Event): Promise<StartSpeechSynthesisTaskCommandOutput> { | ||
log.info('incoming event', JSON.stringify(event)) | ||
const rec: S3Event['Records'] = event.Records | ||
const fileName: string = rec[0].s3.object.key | ||
log.info('processing file', fileName) | ||
|
||
return BucketUtils.downloadFile(fileName) | ||
.then((data: any) => { | ||
return data?.Body?.transformToString(); | ||
let text: string | undefined | ||
let createDetailsMp3: StartSpeechSynthesisTaskCommandOutput | ||
let createDetailsCsv: PutObjectCommandOutput | ||
|
||
return await BucketUtils.downloadFile(fileName) | ||
.then(async (data: GetObjectCommandOutput) => { | ||
return await data?.Body?.transformToString() | ||
}) | ||
.then((eulaText: string | undefined) => { | ||
log.debug('EULA text is', eulaText); | ||
.then(async (eulaText: string | undefined) => { | ||
log.debug('EULA text is', eulaText) | ||
if (eulaText?.length === 0) { | ||
throw new Error(`No content for file ${fileName}`); | ||
throw new Error(`No content for file ${fileName}`) | ||
} | ||
text = eulaText; | ||
// raise Exception unless eulaText has value | ||
// const chunks: RegExpMatchArray | null | undefined = eulaText?.match(/[\s\S]{1,2999}/g) | ||
const chunks: any = eulaText?.match(/[\s\S]{1,2999}/g); | ||
return PollyUtils.startSynthesizeSpeech(chunks); | ||
text = eulaText | ||
const chunks: RegExpMatchArray = Utils.chunkText(eulaText, 2999) | ||
return await PollyUtils.startSynthesizeSpeech(chunks) | ||
}) | ||
.then((mp3Generation: StartSpeechSynthesisTaskOutput | null) => { | ||
createDetailsMp3 = mp3Generation; | ||
log.debug('mp3 file location', JSON.stringify(mp3Generation)); | ||
.then((mp3Generation: StartSpeechSynthesisTaskCommandOutput) => { | ||
createDetailsMp3 = mp3Generation | ||
log.debug('mp3 file location', JSON.stringify(mp3Generation)) | ||
}) | ||
.then((ret: any) => { | ||
const chunks: RegExpMatchArray | null | undefined = text?.match(/[\s\S]{1,4900}/g); | ||
.then(async () => { | ||
const chunks: RegExpMatchArray = Utils.chunkText(text, 4900) | ||
// raise error if chunks has no value | ||
return ComprehendUtils.detectKeyPhrases(chunks); | ||
return await ComprehendUtils.detectKeyPhrases(chunks) | ||
}) | ||
.then(async (kp: DetectKeyPhrasesCommandOutput) => { | ||
const vals = Utils.sortEntriesByValues(kp.KeyPhrases) | ||
const csv = Utils.mapToCsv(vals) | ||
return await BucketUtils | ||
.uploadFile(`uploaded/${fileName.replace('txt', 'csv')}`, csv) | ||
}) | ||
.then((kp: any) => { | ||
const vals = Utils.sortEntriesByValues(kp?.KeyPhrases); | ||
const csv = Utils.mapToCsv(vals); | ||
return BucketUtils | ||
.uploadFile(`uploaded/${fileName.replace('txt', 'csv')}`, csv); | ||
.then(async (uploadCsv: PutObjectCommandOutput) => { | ||
createDetailsCsv = uploadCsv | ||
log.debug('uploaded CSV file', JSON.stringify(uploadCsv)) | ||
return await BucketUtils.deleteFile(fileName) | ||
}) | ||
.then((uploadCsv: any) => { | ||
createDetailsCsv = uploadCsv; | ||
log.debug('uploaded CSV file', JSON.stringify(uploadCsv)); | ||
return BucketUtils.deleteFile(fileName); | ||
.then((cdMp3: DeleteObjectCommandOutput) => { | ||
console.log('mp3 file details', JSON.stringify(createDetailsMp3)) | ||
console.log('CSV file details', JSON.stringify(createDetailsCsv)) | ||
return createDetailsMp3 | ||
}) | ||
.then((cdMp3: any) => { | ||
console.log('mp3 file details', JSON.stringify(createDetailsMp3)); | ||
console.log('CSV file details', JSON.stringify(createDetailsCsv)); | ||
return createDetailsMp3; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import { | ||
ComprehendClient, | ||
DetectKeyPhrasesCommand, | ||
DetectKeyPhrasesCommandOutput, | ||
type DetectKeyPhrasesCommandOutput, | ||
DetectSentimentCommand, | ||
DetectSentimentCommandOutput | ||
} from '@aws-sdk/client-comprehend'; | ||
type DetectSentimentCommandOutput | ||
} from '@aws-sdk/client-comprehend' | ||
|
||
const comprehendClient = new ComprehendClient({}); | ||
const comprehendClient = new ComprehendClient({}) | ||
|
||
export function detectSentiment(text: RegExpMatchArray | null): Promise<DetectSentimentCommandOutput> | null { | ||
if (!text) { | ||
throw new Error('Empty text'); | ||
export async function detectSentiment (text: RegExpMatchArray): Promise<DetectSentimentCommandOutput> { | ||
if (text == null) { | ||
throw new Error('Empty text in detectSentiment') | ||
} | ||
const command = new DetectSentimentCommand({ | ||
LanguageCode: 'en', | ||
Text: text![0] | ||
}); | ||
return comprehendClient.send(command); | ||
Text: text[0] | ||
}) | ||
return await comprehendClient.send(command) | ||
}; | ||
|
||
export function detectKeyPhrases(text: RegExpMatchArray | null | undefined): Promise<DetectKeyPhrasesCommandOutput> | null { | ||
if (!text) { | ||
throw new Error('Empty text'); | ||
export async function detectKeyPhrases (text: RegExpMatchArray): Promise<DetectKeyPhrasesCommandOutput> { | ||
if (text == null) { | ||
throw new Error('Empty text in detectKeyPhrases') | ||
} | ||
const command = new DetectKeyPhrasesCommand({ | ||
LanguageCode: 'en', | ||
Text: text![0] | ||
}); | ||
return comprehendClient.send(command); | ||
Text: text[0] | ||
}) | ||
return await comprehendClient.send(command) | ||
}; |
Oops, something went wrong.