diff --git a/src/commands/parseall.ts b/src/commands/parseall.ts index 7c6a452..f7a34e8 100644 --- a/src/commands/parseall.ts +++ b/src/commands/parseall.ts @@ -26,24 +26,20 @@ export default class Parseall extends Command { embed.setTimestamp(); const search = await this.client.db.Account.find(); - const certificates = search.map((a) => { - let certFile: string; - try { - certFile = readdirSync(`${a.homepath}/Validation`)[0]; // eslint-disable-line - } catch (error) { - if (error.message.includes('no such file or directory') || error.message.includes('File doesn\'t exist.')) certFile = 'not_found.crt'; - else throw error; - } - return parseCertificate(this.client, `${a.homepath}/Validation/${certFile}`); + const files = search.map((acc) => { + let certfile: string; + try { certfile = readdirSync(`${acc.homepath}/Validation`)[0] } catch (error) { if (error.message.includes('no such file or directory') || error.message.includes('File doesn\'t exist.')) certfile = 'not_found.crt' } // eslint-disable-line + return `${acc.homepath}/Validation/${certfile}`; }); - // @ts-ignore - const parsed: Promise<{status: 'fulfilled', value: Certificate}>[] | Promise<{status: 'rejected', reason: Error}>[] = await Promise.allSettled(certificates); - const final = await search.map(async (a) => { + // @ts-ignore + const parsed = await Promise.allSettled(files.map((c) => parseCertificate(this.client, c))); + + const final = search.map(async (a) => { const result = await parsed[search.findIndex((acc) => acc === a)]; if (result.status === 'rejected') { if (result.reason.message.includes('no such file or directory') || result.reason.message.includes('File doesn\'t exist.')) return `${this.client.stores.emojis.error} **${a.username}** Unable to locate certificate`; - if (result.reason.message.includes('panic: Certificate PEM Encode == nil')) return `${this.client.stores.emojis.error} ** ${a.username}** Invalid certificate`; + if (result.reason.message.includes('panic: Certificate PEM Encode == nil')) return `${this.client.stores.emojis.error} **${a.username}** Invalid certificate`; throw result.reason; } const { notAfter } = result.value;