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,20 +26,16 @@ 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`;