Use Promise.allSettled

merge-requests/4/head
Bsian 2020-01-04 13:47:54 +00:00
parent 2e1bf68cc0
commit 350e5c021d
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 23 additions and 22 deletions

View File

@ -4,7 +4,7 @@ import { readdirSync } from 'fs';
import moment from 'moment';
import { Client } from '..';
import { Command, RichEmbed } from '../class';
import { parseCertificate } from '../functions';
import { parseCertificate, Certificate } from '../functions';
export default class Parseall extends Command {
constructor(client: Client) {
@ -36,11 +36,17 @@ export default class Parseall extends Command {
}
return parseCertificate(this.client, `${a.homepath}/Validation/${certFile}`);
});
// @ts-ignore
const parsed: {status: 'fulfilled', value: Certificate}[] | {status: 'rejected', reason: Error}[] = await Promise.allSettled(certificates);
const final = search.map(async (a) => {
try {
const parsed = await Promise.all(certificates);
const { notAfter } = parsed[search.findIndex((acc) => acc === a)];
const result = 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`;
throw result.reason;
}
const { notAfter } = result.value;
// @ts-ignore
const timeObject: {years: number, months: number, days: number, hours: number, minutes: number, seconds: number, firstDateWasLater: boolean} = moment.preciseDiff(new Date(), notAfter, true);
const precise: [number, string][] = [];
@ -55,11 +61,6 @@ export default class Parseall extends Command {
if (notAfter < new Date()) return `${this.client.stores.emojis.error} **${a.username}** Expired ${time} ago`;
return `${this.client.stores.emojis.success} **${a.username}** Expires in ${time}`;
} catch (error) {
if (error.message.includes('no such file or directory') || error.message.includes('File doesn\'t exist.')) return `${this.client.stores.emojis.error} **${a.username}** Unable to locate certificate`;
if (error.message.includes('panic: Certificate PEM Encode == nil')) return `${this.client.stores.emojis.error} ** ${a.username}** Invalid certificate`;
throw error;
}
});
if (final.join('\n').length < 2048) embed.setDescription(final.join('\n'));