Comparing version 0.0.1-2 to 0.0.2
46
index.js
@@ -5,4 +5,4 @@ var net = require('net'); | ||
var assert = require('assert'); | ||
var needle = require('needle'); | ||
var qs = require('querystring'); | ||
var request = require('request'); | ||
var Multipart = require('multipart-stream'); | ||
@@ -22,20 +22,24 @@ var package = JSON.parse(fs.readFileSync(__dirname + '/package.json')); | ||
if(args) opts.arg = args; | ||
var query = qs.stringify(opts); | ||
var data = getFileArgs(files); | ||
var uri = 'http://' + address + API_PATH + path + '?' + query; | ||
needle.post(uri, data, { | ||
multipart: files != null, | ||
user_agent: '/node-'+package.name+'/'+package.version+'/' | ||
return request.post({ | ||
uri: 'http://' + address + API_PATH + path, | ||
qs: opts, | ||
useQuerystring: true, | ||
headers: { | ||
'User-Agent': '/node-'+package.name+'/'+package.version+'/' | ||
}, | ||
formData: getFileForm(files) | ||
}, function(err, res, data) { | ||
return cb(err, data); | ||
try { | ||
return cb(JSON.parse(err || 'null'), JSON.parse(data || 'null')); | ||
} catch(e) { | ||
return cb(err, data); | ||
} | ||
}); | ||
} | ||
// TODO: build a multipart readable stream out of other readable streams | ||
function getFileArgs(files) { | ||
function getFileForm(files) { | ||
if(!files) return null; | ||
var output = {}; | ||
if(!Array.isArray(files)) files = [files]; | ||
@@ -49,4 +53,7 @@ | ||
output[i] = { | ||
file: file, | ||
content_type: 'application/octet-stream' | ||
value: fs.createReadStream(file), | ||
options: { | ||
contentType: 'application/octet-stream', | ||
filename: file | ||
} | ||
}; | ||
@@ -56,4 +63,7 @@ | ||
output[i] = { | ||
buffer: file, | ||
content_type: 'application/octet-stream' | ||
value: file, | ||
options: { | ||
contentType: 'application/octet-stream', | ||
filename: '' | ||
} | ||
}; | ||
@@ -60,0 +70,0 @@ } |
var ipfs = require('./')('localhost:5001'); | ||
/*ipfs.add('/Users/mappum/Downloads/and.jpg', function(err, data) { | ||
ipfs.add('/Users/mappum/Downloads/and.jpg', function(err, data) { | ||
if(err) return console.error(err) | ||
console.log(data) | ||
});*/ | ||
ipfs.object.get('QmeZy1fGbwgVSrqbfh9fKQrAWgeyRnj7h8fsHS1oy3k99x', function(err, data) { | ||
}); | ||
/* | ||
ipfs.cat('Qmbvkmk9LFsGneteXk3G7YLqtLVME566ho6ibaQZZVHaC9', function(err, data) { | ||
console.log(err, data) | ||
}); | ||
*/ |
{ | ||
"name": "ipfs-api", | ||
"version": "0.0.1-2", | ||
"version": "0.0.2", | ||
"description": "An client library for the IPFS API", | ||
"main": "index.js", | ||
"dependencies": { | ||
"needle": "^0.7.10" | ||
"multipart-stream": "^1.0.0", | ||
"request": "^2.48.0" | ||
}, | ||
@@ -9,0 +10,0 @@ "devDependencies": {}, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4221
134
2
1
+ Addedmultipart-stream@^1.0.0
+ Addedrequest@^2.48.0
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedmultipart-stream@1.0.0(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsandwich-stream@0.0.4(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
- Removedneedle@^0.7.10
- Removediconv-lite@0.4.24(transitive)
- Removedneedle@0.7.11(transitive)