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({

0 commit comments

Comments
 (0)