Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs-inactive/js-ipfs-http-client
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ca12041ccacf^
Choose a base ref
...
head repository: ipfs-inactive/js-ipfs-http-client
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3a63acc17a3d
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Aug 20, 2015

  1. allow sending opts to cmds

    jbenet committed Aug 20, 2015
    Copy the full SHA
    ca12041 View commit details
  2. added refs command

    jbenet committed Aug 20, 2015
    Copy the full SHA
    2dc073b View commit details
  3. v2.2.0

    jbenet committed Aug 20, 2015
    Copy the full SHA
    3a63acc View commit details
Showing with 53 additions and 9 deletions.
  1. +1 −1 package.json
  2. +21 −6 src/index.js
  3. +31 −2 test/test.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ipfs-api",
"version": "2.1.6",
"version": "2.2.0",
"description": "A client library for the IPFS API",
"main": "src/index.js",
"dependencies": {
27 changes: 21 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -23,14 +23,22 @@ function IpfsAPI (host_or_multiaddr, port) {
// -- Internal

function command (name) {
return function (cb) {
return requestAPI(name, null, null, null, cb)
return function (opts, cb) {
if (typeof (opts) === 'function') {
cb = opts
opts = {}
}
return requestAPI(name, null, opts, null, cb)
}
}

function argCommand (name) {
return function (arg, cb) {
return requestAPI(name, arg, null, null, cb)
return function (arg, opts, cb) {
if (typeof (opts) === 'function') {
cb = opts
opts = {}
}
return requestAPI(name, arg, opts, null, cb)
}
}

@@ -52,8 +60,12 @@ function IpfsAPI (host_or_multiaddr, port) {

self.config = {
get: argCommand('config'),
set: function (key, value, cb) {
return requestAPI('config', [key, value], null, null, cb)
set: function (key, value, opts, cb) {
if (typeof (opts) === 'function') {
cb = opts
opts = {}
}
return requestAPI('config', [key, value], opts, null, cb)
},
show: function (cb) {
return requestAPI('config/show', null, null, null, true, cb)
@@ -176,6 +188,9 @@ function IpfsAPI (host_or_multiaddr, port) {
resolve: argCommand('name/resolve')
}

self.refs = argCommand('refs')
self.refs.local = command('refs/local')

self.dht = {
findprovs: argCommand('dht/findprovs'),

33 changes: 31 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -102,14 +102,27 @@ describe('ipfs node api', function () {
})
})

var initDocs = 'Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj'
var initDocsLs = {
'help': 'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7',
'about': 'QmfE3nUohq2nEYwieF7YFnJF1VfiL4i3wDxkMq8aGUg8Mt',
'readme': 'QmUFtMrBHqdjTtbebsL6YGebvjShh3Jud1insUv12fEVdA',
'contact': 'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y',
'quick-start': 'QmeEqpsKrvdhuuuVsguHaVdJcPnnUHHZ5qEWjCHavYbNqU',
'security-notes': 'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ'
}
it('ls', function (done) {
this.timeout(10000)

ipfs.ls('Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj', function (err, res) {
ipfs.ls(initDocs, function (err, res) {
if (err) throw err

var dir = res.Objects[0]
assert.equal(dir.Hash, 'Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj')
for (var i in dir.Links) {
var link = dir.Links[i]
assert.equal(link.Hash, initDocsLs[link.Name])
}
assert.equal(dir.Hash, initDocs)
assert.equal(dir.Links.length, 6)
assert.equal(dir.Links[0].Name, 'about')
assert.equal(dir.Links[5].Name, 'security-notes')
@@ -219,6 +232,22 @@ describe('ipfs node api', function () {
})
})

it('refs', function (done) {
this.timeout(10000)
ipfs.refs(initDocs, {'format': '<src> <dst> <linkname>'}, function (err, objs) {
if (err) throw err
for (var i in objs) {
var ref = objs[i]
var refp = ref.Ref.replace('\n', '').split(' ')
assert.equal(refp[0], initDocs)
assert(initDocsLs[refp[2]])
assert.equal(refp[1], initDocsLs[refp[2]])
assert.equal(ref.Err, '')
}
done()
})
})

it('id', function (done) {
this.timeout(10000)
ipfs.id(function (err, res) {