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
|
- name: Use Node.js
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 12.x
|
node-version: 14.6
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
|
|
|
@ -78,3 +78,4 @@ docker/data
|
||||||
# Cache files
|
# Cache files
|
||||||
__pycache__
|
__pycache__
|
||||||
/.idea/
|
/.idea/
|
||||||
|
/venv/
|
||||||
|
|
|
@ -55,7 +55,6 @@ services:
|
||||||
- 80
|
- 80
|
||||||
depends_on:
|
depends_on:
|
||||||
- docker-host
|
- docker-host
|
||||||
- health-check
|
|
||||||
- handshake-api
|
- handshake-api
|
||||||
|
|
||||||
handshake:
|
handshake:
|
||||||
|
@ -115,7 +114,6 @@ services:
|
||||||
expose:
|
expose:
|
||||||
- 3100
|
- 3100
|
||||||
depends_on:
|
depends_on:
|
||||||
- docker-host
|
- caddy
|
||||||
- handshake
|
- handshake
|
||||||
- handshake-api
|
- handshake-api
|
||||||
- caddy
|
|
||||||
|
|
|
@ -19,7 +19,8 @@ const clientOptions = {
|
||||||
};
|
};
|
||||||
const client = new NodeClient(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 getDomainRecords = async (name) => {
|
||||||
const response = await client.execute("getnameresource", [name]);
|
const response = await client.execute("getnameresource", [name]);
|
||||||
|
@ -31,7 +32,13 @@ const getDomainRecords = async (name) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const findSkylinkRecord = (records) => {
|
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) => {
|
const getSkylinkFromRecord = (record) => {
|
||||||
|
@ -69,7 +76,10 @@ server.use(
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
userResHeaderDecorator(headers, userReq, userRes, proxyReq, proxyRes) {
|
userResHeaderDecorator(headers, userReq, userRes, proxyReq, proxyRes) {
|
||||||
if (headers.location && headers.location.match(startsWithSkylinkRegExp)) {
|
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;
|
return headers;
|
||||||
|
|
Reference in New Issue