This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,4 @@ test/test-data/go-ipfs-repo/LOG.old | |
|
||
# while testing npm5 | ||
package-lock.json | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict' | ||
const print = require('../utils').print | ||
|
||
module.exports = { | ||
command: 'dns <domain>', | ||
|
||
describe: 'Resolve DNS links', | ||
|
||
builder: { | ||
format: { | ||
type: 'string' | ||
} | ||
}, | ||
|
||
handler (argv) { | ||
argv.ipfs.dns(argv['domain'], (err, path) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
print(path) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict' | ||
|
||
// dns-nodejs gets replaced by dns-browser when webpacked/browserified | ||
const dns = require('../runtime/dns-nodejs') | ||
const promisify = require('promisify-es6') | ||
|
||
module.exports = () => { | ||
return promisify((domain, opts, callback) => { | ||
if (typeof domain !== 'string') { | ||
return callback(new Error('Invalid arguments, domain must be a string')) | ||
} | ||
|
||
if (typeof opts === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
|
||
dns(domain, opts, callback) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict' | ||
|
||
module.exports = (domain, opts, callback) => { | ||
domain = encodeURIComponent(domain) | ||
let url = `https://ipfs.io/api/v0/dns?arg=${domain}` | ||
|
||
for (const prop in opts) { | ||
url += `&${prop}=${opts[prop]}` | ||
} | ||
|
||
window.fetch(url, {mode: 'cors'}) | ||
.then((response) => { | ||
return response.json() | ||
}) | ||
.then((response) => { | ||
if (response.Path) { | ||
return callback(null, response.Path) | ||
} else { | ||
return callback(new Error(response.Message)) | ||
} | ||
}) | ||
.catch((error) => { | ||
callback(error) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
|
||
const dns = require('dns') | ||
|
||
module.exports = (domain, opts, callback) => { | ||
dns.resolveTxt(domain, (err, records) => { | ||
if (err) { | ||
return callback(err, null) | ||
} | ||
|
||
// TODO: implement recursive option | ||
|
||
for (const record of records) { | ||
if (record[0].startsWith('dnslink=')) { | ||
return callback(null, record[0].substr(8, record[0].length - 1)) | ||
} | ||
} | ||
|
||
callback(new Error('domain does not have a txt dnslink entry')) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict' | ||
|
||
const boom = require('boom') | ||
|
||
exports = module.exports | ||
|
||
exports.get = (request, reply) => { | ||
if (!request.query.arg) { | ||
return reply({ | ||
Message: "Argument 'domain' is required", | ||
Code: 0 | ||
}).code(400).takeover() | ||
} | ||
|
||
request.server.app.ipfs.dns(request.query.arg, (err, path) => { | ||
if (err) { | ||
return reply(boom.badRequest(err)) | ||
} | ||
|
||
return reply({ | ||
Path: path | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
const resources = require('./../resources') | ||
|
||
module.exports = (server) => { | ||
const api = server.select('API') | ||
|
||
api.route({ | ||
method: '*', | ||
path: '/api/v0/dns', | ||
handler: resources.dns.get | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const runOnAndOff = require('../utils/on-and-off') | ||
|
||
describe('dns', () => runOnAndOff((thing) => { | ||
let ipfs | ||
|
||
before(function () { | ||
this.timeout(60 * 1000) | ||
ipfs = thing.ipfs | ||
}) | ||
|
||
it('dns record for ipfs.io', function () { | ||
this.timeout(60 * 1000) | ||
|
||
return ipfs('ipfs.io').then((res) => { | ||
expect(res.substr(0, 6)).to.eql('/ipfs/') | ||
}) | ||
}) | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
chai.use(dirtyChai) | ||
|
||
module.exports = (ctl) => { | ||
describe('.dns', () => { | ||
it('get dns for ipfs.io', (done) => { | ||
ctl.dns('ipfs.io', (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result).to.exist() | ||
done() | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
|
||
module.exports = (http) => { | ||
describe('/dns', () => { | ||
let api | ||
|
||
before(() => { | ||
api = http.api.server.select('API') | ||
}) | ||
|
||
it('get the id', (done) => { | ||
api.inject({ | ||
method: 'GET', | ||
url: '/api/v0/dns?arg=ipfs.io' | ||
}, (res) => { | ||
expect(res).to.have.property('Path') | ||
done() | ||
}) | ||
}) | ||
}) | ||
} |