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

Commit 5182761

Browse files
authored
Merge pull request #420 from ipfs/feat/generic-spec-compliant
level-up
2 parents 9e90265 + a3d98a8 commit 5182761

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2201
-2298
lines changed

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040
},
4141
"homepage": "https://github.com/ipfs/js-ipfs#readme",
4242
"devDependencies": {
43-
"aegir": "^5.0.1",
43+
"aegir": "^7.0.0",
4444
"buffer-loader": "0.0.1",
4545
"chai": "^3.5.0",
4646
"expose-loader": "^0.7.1",
4747
"form-data": "^1.0.0-rc4",
4848
"gulp": "^3.9.1",
4949
"idb-plus-blob-store": "^1.1.2",
50-
"interface-ipfs-core": "^0.8.0",
50+
"interface-ipfs-core": "^0.13.0",
5151
"left-pad": "^1.1.1",
5252
"lodash": "^4.14.1",
5353
"ncp": "^2.0.0",
@@ -67,8 +67,8 @@
6767
"fs-blob-store": "^5.2.1",
6868
"glob": "^7.0.5",
6969
"hapi": "^14.0.0",
70+
"ipfs-api": "^7.0.0",
7071
"ipfs-bitswap": "^0.6.0",
71-
"ipfs-api": "^6.0.3",
7272
"ipfs-block": "^0.3.0",
7373
"ipfs-block-service": "^0.4.0",
7474
"ipfs-merkle-dag": "^0.6.2",
@@ -80,8 +80,9 @@
8080
"joi": "^9.0.4",
8181
"libp2p-ipfs": "^0.12.1",
8282
"libp2p-ipfs-browser": "^0.12.1",
83-
"lodash.get": "^4.4.0",
84-
"lodash.set": "^4.3.0",
83+
"lodash.get": "^4.4.1",
84+
"lodash.has": "^4.5.2",
85+
"lodash.set": "^4.3.1",
8586
"lodash.sortby": "^4.6.1",
8687
"mafmt": "^2.1.1",
8788
"map-limit": "0.0.1",

src/cli/commands/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module.exports = {
5555
})
5656
}
5757

58-
ipfs.config.show((err, config) => {
58+
ipfs.config.get((err, config) => {
5959
if (err) {
6060
log.error(err)
6161
throw new Error('failed to read the config')
@@ -87,7 +87,7 @@ module.exports = {
8787
})
8888
}
8989

90-
ipfs.config.show((err, originalConfig) => {
90+
ipfs.config.get((err, originalConfig) => {
9191
if (err) {
9292
log.error(err)
9393
throw new Error('failed to read the config')

src/cli/commands/config/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
}
3232

3333
function getConfig (next) {
34-
ipfs.config.show((err, config) => {
34+
ipfs.config.get((err, config) => {
3535
if (err) {
3636
log.error(err)
3737
next(new Error('failed to get the config'))

src/cli/commands/config/show.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
if (err) {
2121
throw err
2222
}
23-
ipfs.config.show((err, config) => {
23+
ipfs.config.get((err, config) => {
2424
if (err) {
2525
throw err
2626
}

src/core/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function IPFS (repoInstance) {
5656
this.block = block(this)
5757
this.object = object(this)
5858
this.libp2p = libp2p(this)
59+
this.swarm = this.libp2p.swarm // for interface-ipfs-core sake
5960
this.files = files(this)
6061
this.cat = files(this).cat // Alias for js-ipfs-api cat
6162
this.bitswap = bitswap(this)

src/core/ipfs/config.js

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,57 @@
11
'use strict'
22

3+
const promisify = require('promisify-es6')
4+
const _get = require('lodash.get')
5+
const _has = require('lodash.has')
6+
const _set = require('lodash.set')
7+
38
module.exports = function config (self) {
49
return {
5-
// cli only feature built with show and replace
6-
// edit: (callback) => {},
7-
replace: (config, callback) => {
10+
get: promisify((key, callback) => {
11+
if (typeof key === 'function') {
12+
callback = key
13+
key = undefined
14+
}
15+
16+
if (!key) {
17+
return self._repo.config.get(callback)
18+
}
19+
20+
if (typeof key !== 'string') {
21+
return callback(new Error('Invalid key type'))
22+
}
23+
24+
self._repo.config.get((err, config) => {
25+
if (err) {
26+
return callback(err)
27+
}
28+
if (_has(config, key)) {
29+
const value = _get(config, key, undefined)
30+
callback(null, value)
31+
} else {
32+
callback(new Error('Key does not exist in config'))
33+
}
34+
})
35+
}),
36+
set: promisify((key, value, callback) => {
37+
if (!key || typeof key !== 'string') {
38+
return callback(new Error('Invalid key type'))
39+
}
40+
41+
if (value === undefined || Buffer.isBuffer(value)) {
42+
return callback(new Error('Invalid value type'))
43+
}
44+
45+
self._repo.config.get((err, config) => {
46+
if (err) {
47+
return callback(err)
48+
}
49+
_set(config, key, value)
50+
self.config.replace(config, callback)
51+
})
52+
}),
53+
replace: promisify((config, callback) => {
854
self._repo.config.set(config, callback)
9-
},
10-
show: (callback) => {
11-
self._repo.config.get(callback)
12-
}
55+
})
1356
}
1457
}

src/core/ipfs/id.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use strict'
22

3+
const promisify = require('promisify-es6')
4+
35
module.exports = function id (self) {
4-
return (opts, callback) => {
6+
return promisify((opts, callback) => {
57
if (typeof opts === 'function') {
68
callback = opts
79
opts = {}
@@ -14,12 +16,12 @@ module.exports = function id (self) {
1416

1517
function ready () {
1618
callback(null, {
17-
ID: self._peerInfo.id.toB58String(),
18-
PublicKey: self._peerInfo.id.pubKey.bytes.toString('base64'),
19-
Addresses: self._peerInfo.multiaddrs.map((ma) => { return ma.toString() }).sort(),
20-
AgentVersion: 'js-ipfs',
21-
ProtocolVersion: '9000'
19+
id: self._peerInfo.id.toB58String(),
20+
publicKey: self._peerInfo.id.pubKey.bytes.toString('base64'),
21+
addresses: self._peerInfo.multiaddrs.map((ma) => { return ma.toString() }).sort(),
22+
agentVersion: 'js-ipfs',
23+
protocolVersion: '9000'
2224
})
2325
}
24-
}
26+
})
2527
}

src/core/ipfs/version.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
'use strict'
22

33
const pkg = require('../../../package.json')
4+
const promisify = require('promisify-es6')
45

56
module.exports = function version (self) {
6-
return (opts, callback) => {
7+
return promisify((opts, callback) => {
78
if (typeof opts === 'function') {
89
callback = opts
910
opts = {}
1011
}
1112

12-
callback(null, pkg.version)
13-
}
13+
callback(null, {
14+
version: pkg.version,
15+
repo: '',
16+
commit: ''
17+
})
18+
})
1419
}

src/http-api/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ exports = module.exports = function HttpApi (repo) {
3838
fs.writeFileSync(apiPath, 'api is on by js-ipfs', {flag: 'w+'})
3939
}
4040

41-
this.ipfs.config.show((err, config) => {
41+
this.ipfs.config.get((err, config) => {
4242
if (err) {
4343
return callback(err)
4444
}

src/http-api/resources/config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ exports.getOrSet = {
6060

6161
if (value === undefined) {
6262
// Get the value of a given key
63-
return request.server.app.ipfs.config.show((err, config) => {
63+
return request.server.app.ipfs.config.get((err, config) => {
6464
if (err) {
6565
log.error(err)
6666
return reply({
@@ -84,7 +84,7 @@ exports.getOrSet = {
8484
})
8585
} else {
8686
// Set the new value of a given key
87-
request.server.app.ipfs.config.show((err, originalConfig) => {
87+
request.server.app.ipfs.config.get((err, originalConfig) => {
8888
if (err) {
8989
log.error(err)
9090
return reply({
@@ -113,8 +113,8 @@ exports.getOrSet = {
113113
}
114114
}
115115

116-
exports.show = (request, reply) => {
117-
return request.server.app.ipfs.config.show((err, config) => {
116+
exports.get = (request, reply) => {
117+
return request.server.app.ipfs.config.get((err, config) => {
118118
if (err) {
119119
log.error(err)
120120
return reply({

src/http-api/resources/id.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ exports = module.exports
66

77
exports.get = (request, reply) => {
88
request.server.app.ipfs.id((err, id) => {
9-
if (err) { return reply(boom.badRequest(err)) }
10-
return reply(id)
9+
if (err) {
10+
return reply(boom.badRequest(err))
11+
}
12+
13+
return reply({
14+
ID: id.id,
15+
PublicKey: id.publicKey,
16+
Addresses: id.addresses,
17+
AgentVersion: id.agentVersion,
18+
ProtocolVersion: id.protocolVersion
19+
})
1120
})
1221
}

src/http-api/resources/swarm.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const debug = require('debug')
44
const log = debug('http-api:block')
55
log.error = debug('http-api:block:error')
6+
const multiaddr = require('multiaddr')
67

78
exports = module.exports
89

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

16+
try {
17+
multiaddr(request.query.arg)
18+
} catch (err) {
19+
return reply("Argument 'addr' is invalid").code(500).takeover()
20+
}
21+
1522
return reply({
1623
addr: request.query.arg
1724
})

src/http-api/resources/version.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,11 @@ const boom = require('boom')
55
exports = module.exports
66

77
exports.get = (request, reply) => {
8-
request.server.app.ipfs.version((err, ipfsVersion) => {
8+
request.server.app.ipfs.version((err, version) => {
99
if (err) {
1010
return reply(boom.badRequest(err))
1111
}
1212

13-
request.server.app.ipfs.repo.version((err, repoVersion) => {
14-
if (err) {
15-
return reply(boom.badRequest(err))
16-
}
17-
18-
reply({
19-
Version: ipfsVersion,
20-
Commit: '',
21-
Repo: repoVersion
22-
})
23-
})
13+
reply(version)
2414
})
2515
}

src/http-api/routes/bootstrap.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ module.exports = (server) => {
88

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

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

3131
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1081
3232
api.route({
33-
method: 'GET',
33+
method: '*',
3434
path: '/api/v0/bootstrap/list',
3535
handler: resources.bootstrap.list
3636
})
3737

3838
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1131
3939
api.route({
40-
method: 'GET',
40+
method: '*',
4141
path: '/api/v0/bootstrap/rm',
4242
handler: resources.bootstrap.rm,
4343
config: {

src/http-api/routes/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = (server) => {
1919
api.route({
2020
method: '*',
2121
path: '/api/v0/config/show',
22-
handler: resources.config.show
22+
handler: resources.config.get
2323
})
2424

2525
api.route({

src/http-api/routes/id.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = (server) => {
66
const api = server.select('API')
77

88
api.route({
9-
method: 'GET',
9+
method: '*',
1010
path: '/api/v0/id',
1111
handler: resources.id.get
1212
})

src/http-api/routes/repo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = (server) => {
77
const api = server.select('API')
88

99
api.route({
10-
method: 'GET',
10+
method: '*',
1111
path: '/api/v0/repo',
1212
handler: resources.repo
1313
})

0 commit comments

Comments
 (0)