Proper solution?
parent
1bae7f52a2
commit
51b888848f
|
@ -26,24 +26,20 @@ export default class Parseall extends Command {
|
||||||
embed.setTimestamp();
|
embed.setTimestamp();
|
||||||
const search = await this.client.db.Account.find();
|
const search = await this.client.db.Account.find();
|
||||||
|
|
||||||
const certificates = search.map((a) => {
|
const files = search.map((acc) => {
|
||||||
let certFile: string;
|
let certfile: string;
|
||||||
try {
|
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
|
||||||
certFile = readdirSync(`${a.homepath}/Validation`)[0]; // eslint-disable-line
|
return `${acc.homepath}/Validation/${certfile}`;
|
||||||
} 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}`);
|
|
||||||
});
|
});
|
||||||
// @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)];
|
const result = await parsed[search.findIndex((acc) => acc === a)];
|
||||||
if (result.status === 'rejected') {
|
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('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;
|
throw result.reason;
|
||||||
}
|
}
|
||||||
const { notAfter } = result.value;
|
const { notAfter } = result.value;
|
||||||
|
|
Loading…
Reference in New Issue