forked from engineering/cloudservices
Use Promise.allSettled
parent
2e1bf68cc0
commit
350e5c021d
|
@ -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,30 +36,31 @@ 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)];
|
||||
// @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][] = [];
|
||||
// @ts-ignore
|
||||
const timeArray: number[] = Object.values(timeObject).filter((v) => typeof v === 'number');
|
||||
timeArray.forEach((t) => { // eslint-disable-line
|
||||
const index = timeArray.indexOf(t);
|
||||
const measurements = ['yr', 'mo', 'd', 'h', 'm', 's'];
|
||||
precise.push([t, measurements[index]]);
|
||||
});
|
||||
const time = precise.filter((n) => n[0]).map(((v) => v.join(''))).join(', ');
|
||||
|
||||
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;
|
||||
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][] = [];
|
||||
// @ts-ignore
|
||||
const timeArray: number[] = Object.values(timeObject).filter((v) => typeof v === 'number');
|
||||
timeArray.forEach((t) => { // eslint-disable-line
|
||||
const index = timeArray.indexOf(t);
|
||||
const measurements = ['yr', 'mo', 'd', 'h', 'm', 's'];
|
||||
precise.push([t, measurements[index]]);
|
||||
});
|
||||
const time = precise.filter((n) => n[0]).map(((v) => v.join(''))).join(', ');
|
||||
|
||||
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}`;
|
||||
});
|
||||
|
||||
if (final.join('\n').length < 2048) embed.setDescription(final.join('\n'));
|
||||
|
|
Loading…
Reference in New Issue