mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-22 22:49:28 -07:00
Add custom request handler for DNS
This commit is contained in:
parent
98d7e680ef
commit
bea7679255
1 changed files with 28 additions and 1 deletions
|
@ -13,9 +13,35 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
const dns = require('dns')
|
||||||
|
const bent = require('bent')
|
||||||
|
const req = bent('GET')
|
||||||
const utils = require('../utils')
|
const utils = require('../utils')
|
||||||
const reURI = /^dns:([a-zA-Z0-9\.\-\_]*)(?:\?(.*))?/
|
const reURI = /^dns:([a-zA-Z0-9\.\-\_]*)(?:\?(.*))?/
|
||||||
|
|
||||||
|
const customRequestHandler = async (spData, opts) => {
|
||||||
|
if (('resolveTxt' in dns)) {
|
||||||
|
const prom = async () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
dns.resolveTxt(spData.profile.display, (err, records) => {
|
||||||
|
if (err) reject(err)
|
||||||
|
resolve(records)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
hostname: spData.profile.display,
|
||||||
|
records: {
|
||||||
|
txt: await prom()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const res = await req(spData.proof.uri, null, { Accept: 'application/json' })
|
||||||
|
const json = await res.json()
|
||||||
|
return json
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const processURI = (uri, opts) => {
|
const processURI = (uri, opts) => {
|
||||||
if (!opts) { opts = {} }
|
if (!opts) { opts = {} }
|
||||||
const match = uri.match(reURI)
|
const match = uri.match(reURI)
|
||||||
|
@ -41,7 +67,8 @@ const processURI = (uri, opts) => {
|
||||||
path: ['records', 'txt'],
|
path: ['records', 'txt'],
|
||||||
relation: 'contains'
|
relation: 'contains'
|
||||||
},
|
},
|
||||||
qr: null
|
qr: null,
|
||||||
|
customRequestHandler: customRequestHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue