fix(core): update
This commit is contained in:
parent
dd8c97b99a
commit
622c65291e
@ -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'
|
||||
}
|
||||
|
28
ts/index.ts
28
ts/index.ts
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user