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

Commit 48a3aeb

Browse files
committed
fix(files.get): add dirs on the browser
1 parent fdf6e01 commit 48a3aeb

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

src/add-to-dagnode-transform.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = function (err, res, send, done) {
99
return done(err)
1010
}
1111
async.map(res, function map (entry, next) {
12+
console.log('RECEIVED', entry.Name)
1213
getDagNode(send, entry.Hash, function (err, node) {
1314
if (err) {
1415
return next(err)

src/api/add-files.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

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

56
module.exports = (send) => {
@@ -9,6 +10,10 @@ module.exports = (send) => {
910
opts = {}
1011
}
1112

13+
if (!isNode) {
14+
return cb(new Error('Recursive uploads are not supported in the browser'))
15+
}
16+
1217
if (typeof (path) !== 'string') {
1318
return cb(new Error('"path" must be a string'))
1419
}

src/get-files-stream.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ function getFilesStream (files, opts) {
122122
content: file
123123
}
124124
}).forEach((file) => {
125+
console.log('SENDING (MULTIPART)', file.path, file.dir)
125126
mp.addPart({
126127
headers: headers(file),
127128
body: file.content

src/request-api.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ function onRes (buffer, cb) {
5656

5757
function requestAPI (config, path, args, qs, files, buffer, cb) {
5858
qs = qs || {}
59+
60+
if (Array.isArray(files)) {
61+
qs.recursive = true
62+
}
63+
5964
if (Array.isArray(path)) path = path.join('/')
6065
if (args && !Array.isArray(args)) args = [args]
6166
if (args) qs.arg = args
@@ -67,10 +72,6 @@ function requestAPI (config, path, args, qs, files, buffer, cb) {
6772
delete qs.r
6873
}
6974

70-
if (!isNode && qs.recursive && path === 'add') {
71-
return cb(new Error('Recursive uploads are not supported in the browser'))
72-
}
73-
7475
qs['stream-channels'] = true
7576

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

131-
// Wraps the 'send' function such that an asynchronous transform may be
132-
// applied to its result before passing it on to either its callback or
133-
// promise.
132+
// Wraps the 'send' function such that an asynchronous
133+
// transform may be applied to its result before
134+
// passing it on to either its callback or promise.
134135
send.withTransform = function (transform) {
135136
return function (path, args, qs, files, buffer, cb) {
136137
if (typeof buffer === 'function') {

0 commit comments

Comments
 (0)