fix(core): update
This commit is contained in:
parent
dd8c97b99a
commit
622c65291e
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartdns',
|
name: '@pushrocks/smartdns',
|
||||||
version: '5.0.1',
|
version: '5.0.2',
|
||||||
description: 'smart dns methods written in TypeScript'
|
description: 'smart dns methods written in TypeScript'
|
||||||
}
|
}
|
||||||
|
16
ts/index.ts
16
ts/index.ts
@ -78,7 +78,7 @@ export class Smartdns {
|
|||||||
try {
|
try {
|
||||||
let myRecordArray: plugins.tsclass.network.IDnsRecord[];
|
let myRecordArray: plugins.tsclass.network.IDnsRecord[];
|
||||||
if (runCycles % 2 === 0 || !plugins.dns) {
|
if (runCycles % 2 === 0 || !plugins.dns) {
|
||||||
myRecordArray = await this.getRecord(recordNameArg, recordTypeArg);
|
myRecordArray = await this.getRecord(recordNameArg, recordTypeArg, 0);
|
||||||
} else {
|
} else {
|
||||||
myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg);
|
myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg);
|
||||||
}
|
}
|
||||||
@ -130,17 +130,27 @@ export class Smartdns {
|
|||||||
|
|
||||||
public async getRecord(
|
public async getRecord(
|
||||||
recordNameArg: string,
|
recordNameArg: string,
|
||||||
recordTypeArg: plugins.tsclass.network.TDnsRecordType
|
recordTypeArg: plugins.tsclass.network.TDnsRecordType,
|
||||||
|
retriesCounterArg = 20,
|
||||||
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||||
const requestUrl = `https://cloudflare-dns.com/dns-query?name=${recordNameArg}&type=${recordTypeArg}&do=1`;
|
const requestUrl = `https://cloudflare-dns.com/dns-query?name=${recordNameArg}&type=${recordTypeArg}&do=1`;
|
||||||
|
const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
|
||||||
|
const getResponseBody = async (counterArg = 0): Promise<IGoogleDNSHTTPSResponse> => {
|
||||||
const response = await plugins.smartrequest.request(requestUrl, {
|
const response = await plugins.smartrequest.request(requestUrl, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
accept: 'application/dns-json',
|
accept: 'application/dns-json',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
|
|
||||||
const responseBody: IGoogleDNSHTTPSResponse = response.body;
|
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) {
|
for (const dnsEntry of responseBody.Answer) {
|
||||||
if (dnsEntry.data.startsWith('"') && dnsEntry.data.endsWith('"')) {
|
if (dnsEntry.data.startsWith('"') && dnsEntry.data.endsWith('"')) {
|
||||||
dnsEntry.data = dnsEntry.data.replace(/^"(.*)"$/, '$1');
|
dnsEntry.data = dnsEntry.data.replace(/^"(.*)"$/, '$1');
|
||||||
|
Loading…
Reference in New Issue
Block a user