Merge pull request #322 from NebulousLabs/hns-sia-prefix
HNS sia prefix
This commit is contained in:
commit
a7ed72fb1d
|
@ -11,7 +11,7 @@ jobs:
|
|||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12.x
|
||||
node-version: 14.6
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn
|
||||
|
|
|
@ -78,3 +78,4 @@ docker/data
|
|||
# Cache files
|
||||
__pycache__
|
||||
/.idea/
|
||||
/venv/
|
||||
|
|
|
@ -55,7 +55,6 @@ services:
|
|||
- 80
|
||||
depends_on:
|
||||
- docker-host
|
||||
- health-check
|
||||
- handshake-api
|
||||
|
||||
handshake:
|
||||
|
@ -115,7 +114,6 @@ services:
|
|||
expose:
|
||||
- 3100
|
||||
depends_on:
|
||||
- docker-host
|
||||
- caddy
|
||||
- handshake
|
||||
- handshake-api
|
||||
- caddy
|
||||
|
|
|
@ -19,7 +19,8 @@ const clientOptions = {
|
|||
};
|
||||
const client = new NodeClient(clientOptions);
|
||||
|
||||
const startsWithSkylinkRegExp = /^[a-zA-Z0-9_-]{46}/;
|
||||
// Match both `sia://HASH` and `HASH` links.
|
||||
const startsWithSkylinkRegExp = /^(sia:\/\/)?[a-zA-Z0-9_-]{46}/;
|
||||
|
||||
const getDomainRecords = async (name) => {
|
||||
const response = await client.execute("getnameresource", [name]);
|
||||
|
@ -31,7 +32,13 @@ const getDomainRecords = async (name) => {
|
|||
};
|
||||
|
||||
const findSkylinkRecord = (records) => {
|
||||
return records?.find(({ txt }) => txt?.some((entry) => isValidSkylink(entry)));
|
||||
// Find the last one, so people can update their domains in a non-destructive
|
||||
// way by simply adding a new link. This will also allow keeping links to
|
||||
// older versions for backwards compatibility.
|
||||
return records
|
||||
?.slice()
|
||||
.reverse()
|
||||
.find(({ txt }) => txt?.some((entry) => isValidSkylink(entry)));
|
||||
};
|
||||
|
||||
const getSkylinkFromRecord = (record) => {
|
||||
|
@ -69,7 +76,10 @@ server.use(
|
|||
// eslint-disable-next-line no-unused-vars
|
||||
userResHeaderDecorator(headers, userReq, userRes, proxyReq, proxyRes) {
|
||||
if (headers.location && headers.location.match(startsWithSkylinkRegExp)) {
|
||||
headers.location = headers.location.replace(startsWithSkylinkRegExp, `/hns/${userReq.params.name}`);
|
||||
headers.location = headers.location.replace(
|
||||
startsWithSkylinkRegExp,
|
||||
`/hns/${userReq.params.name.replace("sia://", "")}`
|
||||
);
|
||||
}
|
||||
|
||||
return headers;
|
||||
|
|
Reference in New Issue