Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

level-up #420

Merged
merged 8 commits into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
},
"homepage": "https://github.com/ipfs/js-ipfs#readme",
"devDependencies": {
"aegir": "^5.0.1",
"aegir": "^7.0.0",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"expose-loader": "^0.7.1",
"form-data": "^1.0.0-rc4",
"gulp": "^3.9.1",
"idb-plus-blob-store": "^1.1.2",
"interface-ipfs-core": "^0.8.0",
"interface-ipfs-core": "^0.13.0",
"left-pad": "^1.1.1",
"lodash": "^4.14.1",
"ncp": "^2.0.0",
Expand All @@ -67,8 +67,8 @@
"fs-blob-store": "^5.2.1",
"glob": "^7.0.5",
"hapi": "^14.0.0",
"ipfs-api": "^7.0.0",
"ipfs-bitswap": "^0.6.0",
"ipfs-api": "^6.0.3",
"ipfs-block": "^0.3.0",
"ipfs-block-service": "^0.4.0",
"ipfs-merkle-dag": "^0.6.2",
Expand All @@ -80,8 +80,9 @@
"joi": "^9.0.4",
"libp2p-ipfs": "^0.12.1",
"libp2p-ipfs-browser": "^0.12.1",
"lodash.get": "^4.4.0",
"lodash.set": "^4.3.0",
"lodash.get": "^4.4.1",
"lodash.has": "^4.5.2",
"lodash.set": "^4.3.1",
"lodash.sortby": "^4.6.1",
"mafmt": "^2.1.1",
"map-limit": "0.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = {
})
}

ipfs.config.show((err, config) => {
ipfs.config.get((err, config) => {
if (err) {
log.error(err)
throw new Error('failed to read the config')
Expand Down Expand Up @@ -87,7 +87,7 @@ module.exports = {
})
}

ipfs.config.show((err, originalConfig) => {
ipfs.config.get((err, originalConfig) => {
if (err) {
log.error(err)
throw new Error('failed to read the config')
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/config/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
}

function getConfig (next) {
ipfs.config.show((err, config) => {
ipfs.config.get((err, config) => {
if (err) {
log.error(err)
next(new Error('failed to get the config'))
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/config/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
if (err) {
throw err
}
ipfs.config.show((err, config) => {
ipfs.config.get((err, config) => {
if (err) {
throw err
}
Expand Down
1 change: 1 addition & 0 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function IPFS (repoInstance) {
this.block = block(this)
this.object = object(this)
this.libp2p = libp2p(this)
this.swarm = this.libp2p.swarm // for interface-ipfs-core sake
this.files = files(this)
this.cat = files(this).cat // Alias for js-ipfs-api cat
this.bitswap = bitswap(this)
Expand Down
57 changes: 50 additions & 7 deletions src/core/ipfs/config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,57 @@
'use strict'

const promisify = require('promisify-es6')
const _get = require('lodash.get')
const _has = require('lodash.has')
const _set = require('lodash.set')

module.exports = function config (self) {
return {
// cli only feature built with show and replace
// edit: (callback) => {},
replace: (config, callback) => {
get: promisify((key, callback) => {
if (typeof key === 'function') {
callback = key
key = undefined
}

if (!key) {
return self._repo.config.get(callback)
}

if (typeof key !== 'string') {
return callback(new Error('Invalid key type'))
}

self._repo.config.get((err, config) => {
if (err) {
return callback(err)
}
if (_has(config, key)) {
const value = _get(config, key, undefined)
callback(null, value)
} else {
callback(new Error('Key does not exist in config'))
}
})
}),
set: promisify((key, value, callback) => {
if (!key || typeof key !== 'string') {
return callback(new Error('Invalid key type'))
}

if (value === undefined || Buffer.isBuffer(value)) {
return callback(new Error('Invalid value type'))
}

self._repo.config.get((err, config) => {
if (err) {
return callback(err)
}
_set(config, key, value)
self.config.replace(config, callback)
})
}),
replace: promisify((config, callback) => {
self._repo.config.set(config, callback)
},
show: (callback) => {
self._repo.config.get(callback)
}
})
}
}
16 changes: 9 additions & 7 deletions src/core/ipfs/id.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict'

const promisify = require('promisify-es6')

module.exports = function id (self) {
return (opts, callback) => {
return promisify((opts, callback) => {
if (typeof opts === 'function') {
callback = opts
opts = {}
Expand All @@ -14,12 +16,12 @@ module.exports = function id (self) {

function ready () {
callback(null, {
ID: self._peerInfo.id.toB58String(),
PublicKey: self._peerInfo.id.pubKey.bytes.toString('base64'),
Addresses: self._peerInfo.multiaddrs.map((ma) => { return ma.toString() }).sort(),
AgentVersion: 'js-ipfs',
ProtocolVersion: '9000'
id: self._peerInfo.id.toB58String(),
publicKey: self._peerInfo.id.pubKey.bytes.toString('base64'),
addresses: self._peerInfo.multiaddrs.map((ma) => { return ma.toString() }).sort(),
agentVersion: 'js-ipfs',
protocolVersion: '9000'
})
}
}
})
}
11 changes: 8 additions & 3 deletions src/core/ipfs/version.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
'use strict'

const pkg = require('../../../package.json')
const promisify = require('promisify-es6')

module.exports = function version (self) {
return (opts, callback) => {
return promisify((opts, callback) => {
if (typeof opts === 'function') {
callback = opts
opts = {}
}

callback(null, pkg.version)
}
callback(null, {
version: pkg.version,
repo: '',
commit: ''
})
})
}
2 changes: 1 addition & 1 deletion src/http-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exports = module.exports = function HttpApi (repo) {
fs.writeFileSync(apiPath, 'api is on by js-ipfs', {flag: 'w+'})
}

this.ipfs.config.show((err, config) => {
this.ipfs.config.get((err, config) => {
if (err) {
return callback(err)
}
Expand Down
8 changes: 4 additions & 4 deletions src/http-api/resources/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ exports.getOrSet = {

if (value === undefined) {
// Get the value of a given key
return request.server.app.ipfs.config.show((err, config) => {
return request.server.app.ipfs.config.get((err, config) => {
if (err) {
log.error(err)
return reply({
Expand All @@ -84,7 +84,7 @@ exports.getOrSet = {
})
} else {
// Set the new value of a given key
request.server.app.ipfs.config.show((err, originalConfig) => {
request.server.app.ipfs.config.get((err, originalConfig) => {
if (err) {
log.error(err)
return reply({
Expand Down Expand Up @@ -113,8 +113,8 @@ exports.getOrSet = {
}
}

exports.show = (request, reply) => {
return request.server.app.ipfs.config.show((err, config) => {
exports.get = (request, reply) => {
return request.server.app.ipfs.config.get((err, config) => {
if (err) {
log.error(err)
return reply({
Expand Down
13 changes: 11 additions & 2 deletions src/http-api/resources/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ exports = module.exports

exports.get = (request, reply) => {
request.server.app.ipfs.id((err, id) => {
if (err) { return reply(boom.badRequest(err)) }
return reply(id)
if (err) {
return reply(boom.badRequest(err))
}

return reply({
ID: id.id,
PublicKey: id.publicKey,
Addresses: id.addresses,
AgentVersion: id.agentVersion,
ProtocolVersion: id.protocolVersion
})
})
}
7 changes: 7 additions & 0 deletions src/http-api/resources/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const debug = require('debug')
const log = debug('http-api:block')
log.error = debug('http-api:block:error')
const multiaddr = require('multiaddr')

exports = module.exports

Expand All @@ -12,6 +13,12 @@ exports.parseAddrs = (request, reply) => {
return reply("Argument 'addr' is required").code(400).takeover()
}

try {
multiaddr(request.query.arg)
} catch (err) {
return reply("Argument 'addr' is invalid").code(500).takeover()
}

return reply({
addr: request.query.arg
})
Expand Down
14 changes: 2 additions & 12 deletions src/http-api/resources/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,11 @@ const boom = require('boom')
exports = module.exports

exports.get = (request, reply) => {
request.server.app.ipfs.version((err, ipfsVersion) => {
request.server.app.ipfs.version((err, version) => {
if (err) {
return reply(boom.badRequest(err))
}

request.server.app.ipfs.repo.version((err, repoVersion) => {
if (err) {
return reply(boom.badRequest(err))
}

reply({
Version: ipfsVersion,
Commit: '',
Repo: repoVersion
})
})
reply(version)
})
}
8 changes: 4 additions & 4 deletions src/http-api/routes/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ module.exports = (server) => {

// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L818
api.route({
method: 'GET',
method: '*',
path: '/api/v0/bootstrap',
handler: resources.bootstrap.list
})

// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L866
api.route({
method: 'GET',
method: '*',
path: '/api/v0/bootstrap/add',
handler: resources.bootstrap.add,
config: {
Expand All @@ -30,14 +30,14 @@ module.exports = (server) => {

// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1081
api.route({
method: 'GET',
method: '*',
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',
method: '*',
path: '/api/v0/bootstrap/rm',
handler: resources.bootstrap.rm,
config: {
Expand Down
2 changes: 1 addition & 1 deletion src/http-api/routes/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = (server) => {
api.route({
method: '*',
path: '/api/v0/config/show',
handler: resources.config.show
handler: resources.config.get
})

api.route({
Expand Down
2 changes: 1 addition & 1 deletion src/http-api/routes/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = (server) => {
const api = server.select('API')

api.route({
method: 'GET',
method: '*',
path: '/api/v0/id',
handler: resources.id.get
})
Expand Down
2 changes: 1 addition & 1 deletion src/http-api/routes/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (server) => {
const api = server.select('API')

api.route({
method: 'GET',
method: '*',
path: '/api/v0/repo',
handler: resources.repo
})
Expand Down
Loading