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

Commit

Permalink
fix(files.get): add dirs on the browser
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Aug 9, 2016
1 parent fdf6e01 commit 48a3aeb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/add-to-dagnode-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = function (err, res, send, done) {
return done(err)
}
async.map(res, function map (entry, next) {
console.log('RECEIVED', entry.Name)
getDagNode(send, entry.Hash, function (err, node) {
if (err) {
return next(err)
Expand Down
5 changes: 5 additions & 0 deletions src/api/add-files.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const isNode = require('detect-node')
const addToDagNodesTransform = require('../add-to-dagnode-transform')

module.exports = (send) => {
Expand All @@ -9,6 +10,10 @@ module.exports = (send) => {
opts = {}
}

if (!isNode) {
return cb(new Error('Recursive uploads are not supported in the browser'))
}

if (typeof (path) !== 'string') {
return cb(new Error('"path" must be a string'))
}
Expand Down
1 change: 1 addition & 0 deletions src/get-files-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function getFilesStream (files, opts) {
content: file
}
}).forEach((file) => {
console.log('SENDING (MULTIPART)', file.path, file.dir)
mp.addPart({
headers: headers(file),
body: file.content
Expand Down
15 changes: 8 additions & 7 deletions src/request-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ function onRes (buffer, cb) {

function requestAPI (config, path, args, qs, files, buffer, cb) {
qs = qs || {}

if (Array.isArray(files)) {
qs.recursive = true
}

if (Array.isArray(path)) path = path.join('/')
if (args && !Array.isArray(args)) args = [args]
if (args) qs.arg = args
Expand All @@ -67,10 +72,6 @@ function requestAPI (config, path, args, qs, files, buffer, cb) {
delete qs.r
}

if (!isNode && qs.recursive && path === 'add') {
return cb(new Error('Recursive uploads are not supported in the browser'))
}

qs['stream-channels'] = true

let stream
Expand Down Expand Up @@ -128,9 +129,9 @@ exports = module.exports = function getRequestAPI (config) {
return requestAPI(config, path, args, qs, files, buffer, cb)
}

// Wraps the 'send' function such that an asynchronous transform may be
// applied to its result before passing it on to either its callback or
// promise.
// Wraps the 'send' function such that an asynchronous
// transform may be applied to its result before
// passing it on to either its callback or promise.
send.withTransform = function (transform) {
return function (path, args, qs, files, buffer, cb) {
if (typeof buffer === 'function') {
Expand Down

0 comments on commit 48a3aeb

Please sign in to comment.