Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ipfs-api

Package Overview
Dependencies
Maintainers
5
Versions
177
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipfs-api - npm Package Compare versions

Comparing version 2.9.3 to 2.9.7

CONTRIBUTING.md

9

package.json
{
"name": "ipfs-api",
"version": "2.9.3",
"version": "2.9.7",
"description": "A client library for the IPFS API",

@@ -12,2 +12,3 @@ "main": "src/index.js",

"qs": "^6.0.0",
"require-dir": "^0.3.0",
"vinyl": "^1.1.0",

@@ -36,6 +37,10 @@ "vinyl-fs-browser": "^2.1.1-1",

"gulp": "^3.9.0",
"gulp-bump": "^1.0.0",
"gulp-eslint": "^1.0.0",
"gulp-filter": "^3.0.1",
"gulp-git": "^1.6.0",
"gulp-load-plugins": "^1.0.0",
"gulp-mocha": "^2.1.3",
"gulp-size": "^2.0.0",
"gulp-tag-version": "^1.3.0",
"gulp-util": "^3.0.7",

@@ -55,5 +60,5 @@ "https-browserify": "0.0.1",

"raw-loader": "^0.5.1",
"require-dir": "^0.3.0",
"rimraf": "^2.4.3",
"run-sequence": "^1.1.4",
"semver": "^5.1.0",
"stream-equal": "^0.1.7",

@@ -60,0 +65,0 @@ "stream-http": "^2.0.2",

'use strict'
const multiaddr = require('multiaddr')
const loadCommands = require('./load-commands')
const getConfig = require('./config')
const getRequestAPI = require('./request-api')
const Wreck = require('wreck')
const ndjson = require('ndjson')

@@ -12,9 +12,4 @@ exports = module.exports = IpfsAPI

function IpfsAPI (host_or_multiaddr, port, opts) {
const self = this
const config = getConfig()
if (!(self instanceof IpfsAPI)) {
return new IpfsAPI(host_or_multiaddr, port, opts)
}
try {

@@ -48,225 +43,7 @@ const maddr = multiaddr(host_or_multiaddr).nodeAddress()

const requestAPI = getRequestAPI(config)
const cmds = loadCommands(requestAPI)
cmds.send = requestAPI
cmds.Buffer = Buffer
// -- Internal
function command (name) {
return (opts, cb) => {
if (typeof (opts) === 'function') {
cb = opts
opts = {}
}
return requestAPI(name, null, opts, null, cb)
}
}
function argCommand (name) {
return (arg, opts, cb) => {
if (typeof (opts) === 'function') {
cb = opts
opts = {}
}
return requestAPI(name, arg, opts, null, cb)
}
}
// -- Interface
self.send = requestAPI
self.add = (files, opts, cb) => {
if (typeof (opts) === 'function' && cb === undefined) {
cb = opts
opts = {}
}
if (typeof files === 'string' && files.startsWith('http')) {
Wreck.request('GET', files, null, (err, res) => {
if (err) return cb(err)
requestAPI('add', null, opts, res, cb)
})
return
}
requestAPI('add', null, opts, files, cb)
}
self.cat = argCommand('cat')
self.ls = argCommand('ls')
self.config = {
get: argCommand('config'),
set (key, value, opts, cb) {
if (typeof (opts) === 'function') {
cb = opts
opts = {}
}
return requestAPI('config', [key, value], opts, null, cb)
},
show (cb) {
return requestAPI('config/show', null, null, null, true, cb)
},
replace (file, cb) {
return requestAPI('config/replace', null, null, file, cb)
}
}
self.update = {
apply: command('update'),
check: command('update/check'),
log: command('update/log')
}
self.version = command('version')
self.commands = command('commands')
self.mount = (ipfs, ipns, cb) => {
if (typeof ipfs === 'function') {
cb = ipfs
ipfs = null
} else if (typeof ipns === 'function') {
cb = ipns
ipns = null
}
const opts = {}
if (ipfs) opts.f = ipfs
if (ipns) opts.n = ipns
return requestAPI('mount', null, opts, null, cb)
}
self.diag = {
net: command('diag/net'),
sys: command('diag/sys')
}
self.block = {
get: argCommand('block/get'),
put (file, cb) {
if (Array.isArray(file)) {
return cb(null, new Error('block.put() only accepts 1 file'))
}
return requestAPI('block/put', null, null, file, cb)
}
}
self.object = {
get: argCommand('object/get'),
put (file, encoding, cb) {
if (typeof encoding === 'function') {
return cb(null, new Error("Must specify an object encoding ('json' or 'protobuf')"))
}
return requestAPI('object/put', encoding, null, file, cb)
},
data: argCommand('object/data'),
stat: argCommand('object/stat'),
links: argCommand('object/links'),
patch (file, opts, cb) {
return requestAPI('object/patch', [file].concat(opts), null, null, cb)
}
}
self.swarm = {
peers: command('swarm/peers'),
connect: argCommand('swarm/connect')
}
self.ping = (id, cb) => {
return requestAPI('ping', id, { n: 1 }, null, function (err, res) {
if (err) return cb(err, null)
cb(null, res[1])
})
}
self.id = (id, cb) => {
if (typeof id === 'function') {
cb = id
id = null
}
return requestAPI('id', id, null, null, cb)
}
self.pin = {
add (hash, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = null
}
requestAPI('pin/add', hash, opts, null, cb)
},
remove (hash, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = null
}
requestAPI('pin/rm', hash, opts, null, cb)
},
list (type, cb) {
if (typeof type === 'function') {
cb = type
type = null
}
let opts = null
if (type) opts = { type: type }
return requestAPI('pin/ls', null, opts, null, cb)
}
}
self.log = {
tail (cb) {
requestAPI('log/tail', null, {}, null, false, (err, res) => {
if (err) return cb(err)
cb(null, res.pipe(ndjson.parse()))
})
}
}
self.name = {
publish: argCommand('name/publish'),
resolve: argCommand('name/resolve')
}
self.Buffer = Buffer
self.refs = argCommand('refs')
self.refs.local = command('refs/local')
self.dht = {
findprovs: argCommand('dht/findprovs'),
get (key, opts, cb) {
if (typeof (opts) === 'function' && !cb) {
cb = opts
opts = null
}
return requestAPI('dht/get', key, opts, null, (err, res) => {
if (err) return cb(err)
if (!res) return cb(new Error('empty response'))
if (res.length === 0) return cb(new Error('no value returned for key'))
// Inconsistent return values in the browser vs node
if (Array.isArray(res)) {
res = res[0]
}
if (res.Type === 5) {
cb(null, res.Extra)
} else {
cb(res)
}
})
},
put (key, value, opts, cb) {
if (typeof (opts) === 'function' && !cb) {
cb = opts
opts = null
}
return requestAPI('dht/put', [key, value], opts, null, cb)
}
}
return cmds
}

@@ -43,3 +43,4 @@ const webpack = require('webpack')

tls: '{}',
console: '{}'
console: '{}',
'require-dir': '{}'
}

@@ -46,0 +47,0 @@ }

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc