diff --git a/src/http-api/resources/block.js b/src/http-api/resources/block.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/http-api/resources/bootstrap.js b/src/http-api/resources/bootstrap.js new file mode 100644 index 0000000000..8cb6c5d439 --- /dev/null +++ b/src/http-api/resources/bootstrap.js @@ -0,0 +1,27 @@ +const ipfs = require('./../index.js').ipfs +const boom = require('boom') + +exports = module.exports + +exports.list = (request, reply) => { + ipfs.bootstrap.list((err, list) => { + if (err) { + return reply(boom.badRequest(err)) + } + return reply(list) + }) +} + +exports.add = (request, reply) => { +// ipfs.id((err, id) => { +// if (err) { return reply(boom.badRequest(err)) } +// return reply(id) +// }) +} + +exports.rm = (request, reply) => { +// ipfs.id((err, id) => { +// if (err) { return reply(boom.badRequest(err)) } +// return reply(id) +// }) +} diff --git a/src/http-api/resources/config.js b/src/http-api/resources/config.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/http-api/resources/id.js b/src/http-api/resources/id.js index 79b39759e4..58ed34472b 100644 --- a/src/http-api/resources/id.js +++ b/src/http-api/resources/id.js @@ -1,5 +1,3 @@ -'use strict' - const ipfs = require('./../index.js').ipfs const boom = require('boom') diff --git a/src/http-api/resources/index.js b/src/http-api/resources/index.js index 8b370daa81..4aecd49f28 100644 --- a/src/http-api/resources/index.js +++ b/src/http-api/resources/index.js @@ -1,2 +1,7 @@ exports.version = require('./version') exports.id = require('./id') +exports.bootstrap = require('./bootstrap') +exports.repo = require('./repo') +exports.object = require('./object') +exports.config = require('./config') +exports.block = require('./block') diff --git a/src/http-api/resources/object.js b/src/http-api/resources/object.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/http-api/resources/repo.js b/src/http-api/resources/repo.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/http-api/resources/version.js b/src/http-api/resources/version.js index f9a0f4986b..254bb91096 100644 --- a/src/http-api/resources/version.js +++ b/src/http-api/resources/version.js @@ -1,5 +1,3 @@ -'use strict' - const ipfs = require('./../index.js').ipfs const boom = require('boom') diff --git a/src/http-api/routes/block.js b/src/http-api/routes/block.js new file mode 100644 index 0000000000..570365ea0d --- /dev/null +++ b/src/http-api/routes/block.js @@ -0,0 +1,10 @@ +const api = require('./../index.js').server.select('API') +const resources = require('./../resources') + +// TODO + +api.route({ + method: 'GET', + path: '/api/v0/block', + handler: resources.block +}) diff --git a/src/http-api/routes/bootstrap.js b/src/http-api/routes/bootstrap.js index 61935a0526..18e1f32934 100644 --- a/src/http-api/routes/bootstrap.js +++ b/src/http-api/routes/bootstrap.js @@ -1,5 +1,3 @@ -'use strict' - const api = require('./../index.js').server.select('API') const resources = require('./../resources') const Joi = require('joi') @@ -8,18 +6,18 @@ const Joi = require('joi') api.route({ method: 'GET', path: '/api/v0/bootstrap', - handler: resources.version.list + handler: resources.bootstrap.list }) // https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L866 api.route({ method: 'GET', path: '/api/v0/bootstrap/add', - handler: resources.version.add, + handler: resources.bootstrap.add, config: { validate: { query: { - arg: Joi.string(), // multiaddr to add + arg: Joi.string().required(), // multiaddr to add default: Joi.boolean() } } @@ -30,22 +28,20 @@ api.route({ api.route({ method: 'GET', path: '/api/v0/bootstrap/list', - handler: resources.version.list + handler: resources.bootstrap.list }) // https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1131 api.route({ method: 'GET', path: '/api/v0/bootstrap/rm', - handler: resources.version.rm, + handler: resources.bootstrap.rm, config: { validate: { query: { - arg: Joi.string(), // multiaddr to rm + arg: Joi.string().required(), // multiaddr to rm all: Joi.boolean() } } } - }) - diff --git a/src/http-api/routes/config.js b/src/http-api/routes/config.js new file mode 100644 index 0000000000..62be916cc4 --- /dev/null +++ b/src/http-api/routes/config.js @@ -0,0 +1,10 @@ +const api = require('./../index.js').server.select('API') +const resources = require('./../resources') + +// TODO + +api.route({ + method: 'GET', + path: '/api/v0/config', + handler: resources.config +}) diff --git a/src/http-api/routes/id.js b/src/http-api/routes/id.js index 911e50ed76..65c0d842ab 100644 --- a/src/http-api/routes/id.js +++ b/src/http-api/routes/id.js @@ -1,5 +1,3 @@ -'use strict' - const api = require('./../index.js').server.select('API') const resources = require('./../resources') diff --git a/src/http-api/routes/index.js b/src/http-api/routes/index.js index 1a865494dd..bde22e774b 100644 --- a/src/http-api/routes/index.js +++ b/src/http-api/routes/index.js @@ -1,2 +1,7 @@ require('./version') require('./id') +require('./bootstrap') +// require('./block') +// require('./object') +// require('./repo') +// require('./config') diff --git a/src/http-api/routes/object.js b/src/http-api/routes/object.js new file mode 100644 index 0000000000..0bf200f95d --- /dev/null +++ b/src/http-api/routes/object.js @@ -0,0 +1,10 @@ +const api = require('./../index.js').server.select('API') +const resources = require('./../resources') + +// TODO + +api.route({ + method: 'GET', + path: '/api/v0/object', + handler: resources.object +}) diff --git a/src/http-api/routes/repo.js b/src/http-api/routes/repo.js new file mode 100644 index 0000000000..d230c40f30 --- /dev/null +++ b/src/http-api/routes/repo.js @@ -0,0 +1,10 @@ +const api = require('./../index.js').server.select('API') +const resources = require('./../resources') + +// TODO + +api.route({ + method: 'GET', + path: '/api/v0/repo', + handler: resources.repo +}) diff --git a/src/http-api/routes/version.js b/src/http-api/routes/version.js index 5f7f08e8b1..e2a8f2a702 100644 --- a/src/http-api/routes/version.js +++ b/src/http-api/routes/version.js @@ -1,5 +1,3 @@ -'use strict' - const api = require('./../index.js').server.select('API') const resources = require('./../resources') diff --git a/tests/test-http-api/test-bootstrap.js b/tests/test-http-api/test-bootstrap.js index e4e0669326..7c48f225d0 100644 --- a/tests/test-http-api/test-bootstrap.js +++ b/tests/test-http-api/test-bootstrap.js @@ -1,22 +1,104 @@ /* eslint-env mocha */ -// const expect = require('chai').expect +const expect = require('chai').expect +const APIctl = require('ipfs-api') describe('bootstrap', () => { describe('api', () => { - // var api + var api - it.skip('api', (done) => { - // api = require('../../src/http-api').server.select('API') + it('api', (done) => { + api = require('../../src/http-api').server.select('API') done() }) - // TODO + it('list', (done) => { + api.inject({ + method: 'GET', + url: '/api/v0/bootstrap' + }, (res) => { + expect(res.result).to.deep.equal(defaultList) + done() + }) + }) + + it('list 2', (done) => { + api.inject({ + method: 'GET', + url: '/api/v0/bootstrap/list' + }, (res) => { + expect(res.result).to.deep.equal(defaultList) + done() + }) + }) + + it('add', (done) => { + api.inject({ + method: 'GET', + url: '/api/v0/bootstrap/add', + payload: { + arg: '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT' + } + }, (res) => { + done() + }) + }) + + it('rm', (done) => { + api.inject({ + method: 'GET', + url: '/api/v0/bootstrap/rm', + payload: { + arg: '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT' + } + }, (res) => { + done() + }) + }) + + it('confirm list is as expected', (done) => { + api.inject({ + method: 'GET', + url: '/api/v0/bootstrap/list' + }, (res) => { + expect(res.result).to.deep.equal(defaultList) + done() + }) + }) }) describe('gateway', () => {}) describe('using js-ipfs-api', () => { - // TODO + var ctl + + it('start IPFS API ctl', (done) => { + ctl = APIctl('/ip4/127.0.0.1/tcp/6001') + done() + }) + + // TODO: needs https://github.com/ipfs/js-ipfs-api/issues/217 + it.skip('list', (done) => { + ctl.boostrap.list((err, result) => { + expect(err).to.not.exist + expect(result).to.deep.equal(defaultList) + done() + }) + }) + + it.skip('add', (done) => {}) + it.skip('rm', (done) => {}) }) }) + +const defaultList = [ + '/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ', + '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z', + '/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM', + '/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm', + '/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu', + '/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64', + '/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd', + '/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3', + '/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx' +]