Adds DoH capabilities
This commit is contained in:
parent
1f29c385b5
commit
919607ecf3
1 changed files with 1 additions and 42 deletions
43
src/util.js
43
src/util.js
|
|
@ -48,7 +48,7 @@ export async function ensureDir(dir) {
|
||||||
* @param {string} value
|
* @param {string} value
|
||||||
*/
|
*/
|
||||||
const parseTxtRecordData = (value) => {
|
const parseTxtRecordData = (value) => {
|
||||||
throw new Error(value);
|
//throw new Error(value);
|
||||||
const result = {};
|
const result = {};
|
||||||
for (const part of value.split(';')) {
|
for (const part of value.split(';')) {
|
||||||
const [key, ...value] = part.split('=');
|
const [key, ...value] = part.split('=');
|
||||||
|
|
@ -66,27 +66,6 @@ const parseTxtRecordData = (value) => {
|
||||||
export async function findTxtRecord(host) {
|
export async function findTxtRecord(host) {
|
||||||
const resolver = new DohResolver('https://doh.hosterra.tech/dns-query');
|
const resolver = new DohResolver('https://doh.hosterra.tech/dns-query');
|
||||||
const resolved = await resolver.query( '_.' + host );
|
const resolved = await resolver.query( '_.' + host );
|
||||||
/*resolver.query( host)
|
|
||||||
.then(response => {
|
|
||||||
response.answers.forEach(ans => {
|
|
||||||
throw new Error(ans)
|
|
||||||
const txtData = parseTxtRecordData(ans.data);
|
|
||||||
if (txtData[recordParamDestUrl]) {
|
|
||||||
throw new Error(txtData[recordParamDestUrl])
|
|
||||||
return {
|
|
||||||
url: txtData[recordParamDestUrl],
|
|
||||||
httpStatus: txtData[recordParamHttpStatus],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(throw new Error(err));*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//console.log(resolved);
|
|
||||||
//throw new Error(JSON.stringify(resolved));
|
|
||||||
if (resolved.answers) {
|
if (resolved.answers) {
|
||||||
for (const head of resolved.answers) {
|
for (const head of resolved.answers) {
|
||||||
const txtData = parseTxtRecordData(head.data);
|
const txtData = parseTxtRecordData(head.data);
|
||||||
|
|
@ -97,26 +76,6 @@ export async function findTxtRecord(host) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*resolver.query( host)
|
|
||||||
.then(response => {
|
|
||||||
response.answers.forEach(ans => console.log(ans.data));
|
|
||||||
})
|
|
||||||
.catch(err => console.error(err));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const resolve = await request(`https://dns.google/resolve?name=_.${encodeURIComponent(host)}&type=TXT`);
|
|
||||||
if (resolve.data.Answer) {
|
|
||||||
for (const head of resolve.data.Answer) {
|
|
||||||
const txtData = parseTxtRecordData(head.data);
|
|
||||||
if (!txtData[recordParamDestUrl]) continue;
|
|
||||||
return {
|
|
||||||
url: txtData[recordParamDestUrl],
|
|
||||||
httpStatus: txtData[recordParamHttpStatus],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue