fix ts problems
ci / build (push) Failing after 2m5s Details

This commit is contained in:
CJ_Clippy 2024-07-15 23:43:50 -08:00
parent 4b060bf0f9
commit 841c918e5f
1 changed files with 11 additions and 6 deletions

View File

@ -26,7 +26,7 @@ const definitions = [
} }
] ]
function render(template: string, values: ) { function render(template: string, values: any) {
// console.log(`values=${values}`) // console.log(`values=${values}`)
// console.log(values) // console.log(values)
return template.replace(/:([a-zA-Z0-9_]+)/g, (match, key) => { return template.replace(/:([a-zA-Z0-9_]+)/g, (match, key) => {
@ -57,14 +57,19 @@ function render(template: string, values: ) {
export async function checkEmail (body: string): Promise<NotificationData> { export async function checkEmail (body: string): Promise<NotificationData> {
const mail = await simpleParser(body) const mail = await simpleParser(body)
if (!mail) throw new Error('mail object was unable to be gathered from simpleParser');
if (!mail.from) throw new Error('mail.from was empty');
if (!mail.from.value) throw new Error('mail.from.value was empty');
if (!mail.from.value[0]) throw new Error('mail.from.value[0] was empty');
if (!mail.date) throw new Error('mail.date was empty');
if (!mail?.html) { if (!mail?.html) {
console.log(`mail.html was not truthy. This means the e-mail was text-only mode. This also means the e-mail is not a go-live notification.`); console.log(`mail.html was not truthy. This means the e-mail was text-only mode. This also means the e-mail is not a go-live notification.`);
return { isMatch: false } return { isMatch: false }
} }
let res = {} let res: Record<string, any> = {}
let def = definitions.find((def) => def.from === mail.from.value[0].address) let def: any = definitions.find((def) => def.from === mail.from!.value[0]!.address)
if (!def) return { isMatch: false, channel: null, platform: null, url: null }; if (!def) return { isMatch: false, channel: null, platform: undefined, url: undefined };
res.isMatch = true res.isMatch = true
// Step 0, get values from e-mail metadata // Step 0, get values from e-mail metadata
@ -85,8 +90,8 @@ export async function checkEmail (body: string): Promise<NotificationData> {
if (def.regex && res.url) return def.regex.exec(res.url).at(1); if (def.regex && res.url) return def.regex.exec(res.url).at(1);
})() })()
res.userId = res.userId || null res.userId = res.userId || undefined
res.avatar = res.avatar || null res.avatar = res.avatar || undefined
res.url = res.url || render(def.template, { channel: res.channel }) res.url = res.url || render(def.template, { channel: res.channel })