Proper solution?

merge-requests/4/head
Bsian 2020-01-04 15:05:05 +00:00
parent 1bae7f52a2
commit 51b888848f
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 9 additions and 13 deletions

View File

@ -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;