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.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from ipfs/feature/http-api
WIP: Make http-api endpoints as specified by the http-api-spec, for the features present in core
- Loading branch information
Showing
51 changed files
with
824 additions
and
436 deletions.
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
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,32 @@ | ||
const fs = require('fs') | ||
const os = require('os') | ||
const APIctl = require('ipfs-api') | ||
const multiaddr = require('multiaddr') | ||
const debug = require('debug') | ||
const log = debug('cli') | ||
log.error = debug('cli:error') | ||
|
||
exports = module.exports | ||
|
||
const repoPath = process.env.IPFS_PATH || os.homedir() + '/.ipfs' | ||
|
||
exports.isDaemonOn = isDaemonOn | ||
function isDaemonOn () { | ||
try { | ||
fs.readFileSync(repoPath + '/api') | ||
log('daemon is on') | ||
return true | ||
} catch (err) { | ||
log('daemon is off') | ||
return false | ||
} | ||
} | ||
|
||
exports.getAPICtl = () => { | ||
if (!isDaemonOn) { | ||
throw new Error('daemon is not on') | ||
} | ||
|
||
const apiAddr = multiaddr(fs.readFileSync(repoPath + '/api').toString()) | ||
return APIctl(apiAddr.toString()) | ||
} |
This file was deleted.
Oops, something went wrong.
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
Empty file.
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,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) | ||
// }) | ||
} |
Empty file.
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
'use strict' | ||
|
||
const ipfs = require('./../index.js').ipfs | ||
const boom = require('boom') | ||
|
||
|
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 |
---|---|---|
@@ -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') |
Empty file.
Empty file.
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 |
---|---|---|
@@ -1,13 +1,28 @@ | ||
'use strict' | ||
|
||
const ipfs = require('./../index.js').ipfs | ||
const boom = require('boom') | ||
|
||
exports = module.exports | ||
|
||
exports.get = (request, reply) => { | ||
ipfs.version((err, version) => { | ||
if (err) { return reply(boom.badRequest(err)) } | ||
return reply(version) | ||
ipfs.version((err, ipfsVersion) => { | ||
if (err) { | ||
return reply(boom.badRequest(err)) | ||
} | ||
|
||
ipfs.repo.version((err, repoVersion) => { | ||
if (err) { | ||
return reply(boom.badRequest(err)) | ||
} | ||
|
||
console.log('--------->') | ||
|
||
reply({ | ||
Version: ipfsVersion, | ||
Commit: '', | ||
Repo: repoVersion | ||
}).header('Transfer-Encoding', 'chunked') | ||
// .header('Trailer', 'X-Stream-Error') | ||
.type('application/json') | ||
}) | ||
}) | ||
} |
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,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 | ||
}) |
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 |
---|---|---|
@@ -1,22 +1,47 @@ | ||
'use strict' | ||
|
||
const server = require('./../index.js').server | ||
const api = require('./../index.js').server.select('API') | ||
const resources = require('./../resources') | ||
const Joi = require('joi') | ||
|
||
server.route({ | ||
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L818 | ||
api.route({ | ||
method: 'GET', | ||
path: '/api/v0/bootstrap', | ||
handler: resources.version.list | ||
handler: resources.bootstrap.list | ||
}) | ||
|
||
server.route({ | ||
method: 'POST', | ||
path: '/api/v0/bootstrap', | ||
handler: resources.version.add | ||
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L866 | ||
api.route({ | ||
method: 'GET', | ||
path: '/api/v0/bootstrap/add', | ||
handler: resources.bootstrap.add, | ||
config: { | ||
validate: { | ||
query: { | ||
arg: Joi.string().required(), // multiaddr to add | ||
default: Joi.boolean() | ||
} | ||
} | ||
} | ||
}) | ||
|
||
server.route({ | ||
method: 'DELETE', | ||
path: '/api/v0/bootstrap', | ||
handler: resources.version.add | ||
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1081 | ||
api.route({ | ||
method: 'GET', | ||
path: '/api/v0/bootstrap/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.bootstrap.rm, | ||
config: { | ||
validate: { | ||
query: { | ||
arg: Joi.string().required(), // multiaddr to rm | ||
all: Joi.boolean() | ||
} | ||
} | ||
} | ||
}) |
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,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 | ||
}) |
Oops, something went wrong.