Merge pull request #470 from Delivator/hns-api-punycode-fix

Hns api punycode fix (#458 fix)
This commit is contained in:
Karol Wypchło 2020-10-14 14:34:32 +02:00 committed by GitHub
commit 9deb1b014c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 22 deletions

View File

@ -6,7 +6,8 @@
"dependencies": { "dependencies": {
"express": "^4.17.1", "express": "^4.17.1",
"hs-client": "^0.0.9", "hs-client": "^0.0.9",
"node-cache": "^5.1.2" "node-cache": "^5.1.2",
"punycode": "^2.1.1"
}, },
"devDependencies": { "devDependencies": {
"prettier": "^2.0.5" "prettier": "^2.0.5"

View File

@ -1,4 +1,5 @@
const express = require("express"); const express = require("express");
const punycode = require("punycode");
const NodeCache = require("node-cache"); const NodeCache = require("node-cache");
const { NodeClient } = require("hs-client"); const { NodeClient } = require("hs-client");
@ -51,11 +52,12 @@ const getSkylinkFromRecord = (record) => {
const resolveDomainHandler = async (req, res) => { const resolveDomainHandler = async (req, res) => {
try { try {
const records = await getDomainRecords(req.params.name); const domain = punycode.toASCII(req.params.name);
if (!records) return res.status(404).send(`No records found for ${req.params.name}`); const records = await getDomainRecords(domain);
if (!records) return res.status(404).send(`No records found for ${domain}`);
const record = findSkylinkRecord(records); const record = findSkylinkRecord(records);
if (!record) throw new Error(`No skylink found in dns records of ${req.params.name}`); if (!record) throw new Error(`No skylink found in dns records of ${domain}`);
const skylink = getSkylinkFromRecord(record); const skylink = getSkylinkFromRecord(record);
return res.json({ skylink }); return res.json({ skylink });

View File

@ -5734,24 +5734,7 @@ eslint-plugin-react-hooks@^1.7.0:
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-1.7.0.tgz#6210b6d5a37205f0b92858f895a4e827020a7d04" resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-1.7.0.tgz#6210b6d5a37205f0b92858f895a4e827020a7d04"
integrity sha512-iXTCFcOmlWvw4+TOE8CLWj6yX1GwzT0Y6cUfHHZqWnSk144VmVIRcVGtUAzrLES7C798lmvnt02C7rxaOX1HNA== integrity sha512-iXTCFcOmlWvw4+TOE8CLWj6yX1GwzT0Y6cUfHHZqWnSk144VmVIRcVGtUAzrLES7C798lmvnt02C7rxaOX1HNA==
eslint-plugin-react@7.20.6: eslint-plugin-react@7.21.4, eslint-plugin-react@^7.20.6:
version "7.20.6"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.20.6.tgz#4d7845311a93c463493ccfa0a19c9c5d0fd69f60"
integrity sha512-kidMTE5HAEBSLu23CUDvj8dc3LdBU0ri1scwHBZjI41oDv4tjsWZKU7MQccFzH1QYPYhsnTF2ovh7JlcIcmxgg==
dependencies:
array-includes "^3.1.1"
array.prototype.flatmap "^1.2.3"
doctrine "^2.1.0"
has "^1.0.3"
jsx-ast-utils "^2.4.1"
object.entries "^1.1.2"
object.fromentries "^2.0.2"
object.values "^1.1.1"
prop-types "^15.7.2"
resolve "^1.17.0"
string.prototype.matchall "^4.0.2"
eslint-plugin-react@^7.20.6:
version "7.21.4" version "7.21.4"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.21.4.tgz#31060b2e5ff82b12e24a3cc33edb7d12f904775c" resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.21.4.tgz#31060b2e5ff82b12e24a3cc33edb7d12f904775c"
integrity sha512-uHeQ8A0hg0ltNDXFu3qSfFqTNPXm1XithH6/SY318UX76CMj7Q599qWpgmMhVQyvhq36pm7qvoN3pb6/3jsTFg== integrity sha512-uHeQ8A0hg0ltNDXFu3qSfFqTNPXm1XithH6/SY318UX76CMj7Q599qWpgmMhVQyvhq36pm7qvoN3pb6/3jsTFg==