fix(core): update

This commit is contained in:
Philipp Kunz 2022-07-27 11:42:01 +02:00
parent dd8c97b99a
commit 622c65291e
2 changed files with 20 additions and 10 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@pushrocks/smartdns',
version: '5.0.1',
version: '5.0.2',
description: 'smart dns methods written in TypeScript'
}

View File

@ -78,7 +78,7 @@ export class Smartdns {
try {
let myRecordArray: plugins.tsclass.network.IDnsRecord[];
if (runCycles % 2 === 0 || !plugins.dns) {
myRecordArray = await this.getRecord(recordNameArg, recordTypeArg);
myRecordArray = await this.getRecord(recordNameArg, recordTypeArg, 0);
} else {
myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg);
}
@ -130,17 +130,27 @@ export class Smartdns {
public async getRecord(
recordNameArg: string,
recordTypeArg: plugins.tsclass.network.TDnsRecordType
recordTypeArg: plugins.tsclass.network.TDnsRecordType,
retriesCounterArg = 20,
): Promise<plugins.tsclass.network.IDnsRecord[]> {
const requestUrl = `https://cloudflare-dns.com/dns-query?name=${recordNameArg}&type=${recordTypeArg}&do=1`;
const response = await plugins.smartrequest.request(requestUrl, {
method: 'GET',
headers: {
accept: 'application/dns-json',
},
});
const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
const responseBody: IGoogleDNSHTTPSResponse = response.body;
const getResponseBody = async (counterArg = 0): Promise<IGoogleDNSHTTPSResponse> => {
const response = await plugins.smartrequest.request(requestUrl, {
method: 'GET',
headers: {
accept: 'application/dns-json',
},
});
const responseBody: IGoogleDNSHTTPSResponse = response.body;
if (responseBody?.Status !== 0 && counterArg < retriesCounterArg) {
await plugins.smartdelay.delayFor(500);
return getResponseBody(counterArg++);
} else {
return responseBody
}
}
const responseBody = await getResponseBody();
for (const dnsEntry of responseBody.Answer) {
if (dnsEntry.data.startsWith('"') && dnsEntry.data.endsWith('"')) {
dnsEntry.data = dnsEntry.data.replace(/^"(.*)"$/, '$1');