This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
interface-ipfs-core config API spec compliant #307
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,64 @@ | ||
'use strict' | ||
|
||
const argCommand = require('../cmd-helpers').argCommand | ||
const streamifier = require('streamifier') | ||
|
||
module.exports = (send) => { | ||
return { | ||
get: argCommand(send, 'config'), | ||
set (key, value, opts, cb) { | ||
if (typeof (opts) === 'function') { | ||
cb = opts | ||
get (key, callback) { | ||
if (typeof key === 'function') { | ||
callback = key | ||
key = undefined | ||
} | ||
|
||
if (!key) { | ||
return send('config/show', null, null, null, true, callback) | ||
} | ||
|
||
return send('config', key, null, null, (err, result) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
callback(null, result.Value) | ||
}) | ||
}, | ||
set (key, value, opts, callback) { | ||
if (typeof opts === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
if (typeof key !== 'string') { | ||
return callback(new Error('Invalid key type')) | ||
} | ||
|
||
if (typeof value !== 'object' && | ||
typeof value !== 'boolean' && | ||
typeof value !== 'string') { | ||
return callback(new Error('Invalid value type')) | ||
} | ||
|
||
if (typeof (value) === 'object') { | ||
if (typeof value === 'object') { | ||
value = JSON.stringify(value) | ||
opts = { json: true } | ||
} else if (typeof (value) === 'boolean') { | ||
} | ||
|
||
if (typeof value === 'boolean') { | ||
value = value.toString() | ||
opts = { bool: true } | ||
} | ||
|
||
return send('config', [key, value], opts, null, cb) | ||
}, | ||
show (cb) { | ||
return send('config/show', null, null, null, true, cb) | ||
return send('config', [key, value], opts, null, callback) | ||
}, | ||
replace (file, cb) { | ||
return send('config/replace', null, null, file, cb) | ||
replace (config, callback) { | ||
// Its a path | ||
if (typeof config === 'string') { | ||
return send('config/replace', null, null, config, callback) | ||
} | ||
|
||
// Its a config obj | ||
if (typeof config === 'object') { | ||
config = streamifier.createReadStream(new Buffer(JSON.stringify(config))) | ||
return send('config/replace', null, null, config, callback) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just missing to make the config.replace tests to work. It seems that this was never working (see https://github.com/ipfs/js-ipfs-api/blob/master/test/api/config.spec.js#L123-L133), unfortunately. The current problem is that the config never gets replaced and after we send the replace, the content type of the following config.get requests becomes text/plain instead of application/json There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Learned that this is an error in actual go-ipfs ipfs/kubo#2927 |
||
} | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably be valuable for the
send
method to accept a config argument rather than having a parameter list filled withnull
sThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 agree. In fact, what I'm very much thinking is after merging the config-api PR into ipfs-api/ng branch, just make a PR to update how request-api.js works, break the tests (so that we don't have to run 300 tests while developing a single feature) and clean up whatever else I find.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is happening :) 43a1dfa