Commit 69bfad0e by Johannes Zellner

WIP

1 parent 6a1e16e6
...@@ -11,6 +11,8 @@ var superagent = require('superagent'), ...@@ -11,6 +11,8 @@ var superagent = require('superagent'),
readlineSync = require('readline-sync'), readlineSync = require('readline-sync'),
safe = require('safetydance'), safe = require('safetydance'),
async = require('async'), async = require('async'),
ProgressBar = require('progress'),
ProgressStream = require('progress-stream'),
fs = require('fs'), fs = require('fs'),
request = require('request'), request = require('request'),
url = require('url'), url = require('url'),
...@@ -138,18 +140,47 @@ function put(filePath, otherFilePaths, options) { ...@@ -138,18 +140,47 @@ function put(filePath, otherFilePaths, options) {
relativeFilePath = path.basename(file); relativeFilePath = path.basename(file);
} }
var stat = safe.fs.statSync(file);
if (!stat) return callback(safe.error);
var bar = new ProgressBar('[:bar] :percent: :etas', {
complete: '=',
incomplete: ' ',
width: 100,
total: parseInt(stat.size),
stream: process.stdout
});
var destinationPath = (destination ? '/' + destination : '') + '/' + relativeFilePath; var destinationPath = (destination ? '/' + destination : '') + '/' + relativeFilePath;
console.log('Uploading file %s -> %s', relativeFilePath.cyan, destinationPath.cyan); console.log('Uploading file %s -> %s', relativeFilePath.cyan, destinationPath.cyan);
superagent.post(config.server() + API + destinationPath).query(gQuery).attach('file', file).end(function (error, result) { var readStream = fs.createReadStream(file);
if (result && result.statusCode === 403) return callback(new Error('Upload destination ' + destinationPath + ' not allowed')); var progress = new ProgressStream({ time: 50 });
if (result && result.statusCode !== 201) return callback(new Error('Error uploading file: ' + result.statusCode)); progress.on('progress', function (p) { bar.update(p.percentage / 100); /* bar.tick(p.transferred - bar.curr); */ });
if (error) return callback(error); // progress.on('progress', function (p) { console.log(p.percentage); });
progress.setLength(stat.size);
// superagent.post(config.server() + API + destinationPath).query(gQuery).attach('file', file).end(function (error, result) {
var postStream = superagent.post(config.server() + API + destinationPath).query(gQuery);
readStream.pipe(progress).pipe(postStream);
readStream.on('error', function (error) { console.error('Read error:', error); });
postStream.on('error', function (error) { console.error('Post error:', error); });
postStream.on('end', function () {
console.log('Uploaded to ' + config.server() + destinationPath); console.log('Uploaded to ' + config.server() + destinationPath);
callback(null); callback(null);
}); });
// postStream.end(function (error, result) {
// if (result && result.statusCode === 403) return callback(new Error('Upload destination ' + destinationPath + ' not allowed'));
// if (result && result.statusCode !== 201) return callback(new Error('Error uploading file: ' + result.statusCode));
// if (error) return callback(error);
//
// console.log('Uploaded to ' + config.server() + destinationPath);
//
// callback(null);
// });
}, function (error) { }, function (error) {
if (error) { if (error) {
console.log('Failed to put file.', error.message.red); console.log('Failed to put file.', error.message.red);
......
...@@ -124,6 +124,11 @@ ...@@ -124,6 +124,11 @@
} }
} }
}, },
"buffer-shims": {
"version": "1.0.0",
"from": "buffer-shims@>=1.0.0 <1.1.0",
"resolved": "https://registry.npmjs.org/buffer-shims/-/buffer-shims-1.0.0.tgz"
},
"colors": { "colors": {
"version": "1.1.2", "version": "1.1.2",
"from": "colors@>=1.1.2 <2.0.0", "from": "colors@>=1.1.2 <2.0.0",
...@@ -281,6 +286,11 @@ ...@@ -281,6 +286,11 @@
} }
} }
}, },
"core-util-is": {
"version": "1.0.2",
"from": "core-util-is@>=1.0.0 <1.1.0",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz"
},
"debug": { "debug": {
"version": "2.2.0", "version": "2.2.0",
"from": "debug@>=2.2.0 <3.0.0", "from": "debug@>=2.2.0 <3.0.0",
...@@ -806,6 +816,11 @@ ...@@ -806,6 +816,11 @@
"from": "inherits@2.0.3", "from": "inherits@2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz" "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz"
}, },
"isarray": {
"version": "1.0.0",
"from": "isarray@>=1.0.0 <1.1.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
},
"mime-db": { "mime-db": {
"version": "1.26.0", "version": "1.26.0",
"from": "mime-db@>=1.26.0 <1.27.0", "from": "mime-db@>=1.26.0 <1.27.0",
...@@ -1031,6 +1046,26 @@ ...@@ -1031,6 +1046,26 @@
"from": "passport-strategy@>=1.0.0 <2.0.0", "from": "passport-strategy@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz" "resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz"
}, },
"process-nextick-args": {
"version": "1.0.7",
"from": "process-nextick-args@>=1.0.6 <1.1.0",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz"
},
"progress": {
"version": "2.0.0",
"from": "progress@latest",
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz"
},
"progress-stream": {
"version": "2.0.0",
"from": "progress-stream@latest",
"resolved": "https://registry.npmjs.org/progress-stream/-/progress-stream-2.0.0.tgz"
},
"readable-stream": {
"version": "2.2.9",
"from": "readable-stream@>=2.1.5 <3.0.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.2.9.tgz"
},
"readline-sync": { "readline-sync": {
"version": "1.4.6", "version": "1.4.6",
"from": "readline-sync@latest", "from": "readline-sync@latest",
...@@ -1450,11 +1485,21 @@ ...@@ -1450,11 +1485,21 @@
"from": "setprototypeof@1.0.2", "from": "setprototypeof@1.0.2",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.2.tgz" "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.2.tgz"
}, },
"speedometer": {
"version": "1.0.0",
"from": "speedometer@>=1.0.0 <1.1.0",
"resolved": "https://registry.npmjs.org/speedometer/-/speedometer-1.0.0.tgz"
},
"statuses": { "statuses": {
"version": "1.3.1", "version": "1.3.1",
"from": "statuses@>=1.3.1 <2.0.0", "from": "statuses@>=1.3.1 <2.0.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz" "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz"
}, },
"string_decoder": {
"version": "1.0.0",
"from": "string_decoder@>=1.0.0 <1.1.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.0.tgz"
},
"superagent": { "superagent": {
"version": "1.8.1", "version": "1.8.1",
"from": "superagent@>=1.7.2 <2.0.0", "from": "superagent@>=1.7.2 <2.0.0",
...@@ -1560,15 +1605,30 @@ ...@@ -1560,15 +1605,30 @@
} }
} }
}, },
"through2": {
"version": "2.0.3",
"from": "through2@>=2.0.3 <2.1.0",
"resolved": "https://registry.npmjs.org/through2/-/through2-2.0.3.tgz"
},
"underscore": { "underscore": {
"version": "1.8.3", "version": "1.8.3",
"from": "underscore@>=1.8.3 <2.0.0", "from": "underscore@>=1.8.3 <2.0.0",
"resolved": "http://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz" "resolved": "http://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz"
}, },
"util-deprecate": {
"version": "1.0.2",
"from": "util-deprecate@>=1.0.1 <1.1.0",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz"
},
"uuid": { "uuid": {
"version": "3.0.1", "version": "3.0.1",
"from": "uuid@latest", "from": "uuid@latest",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.0.1.tgz" "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.0.1.tgz"
},
"xtend": {
"version": "4.0.1",
"from": "xtend@>=4.0.1 <4.1.0",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz"
} }
} }
} }
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
"passport": "^0.2.2", "passport": "^0.2.2",
"passport-http-bearer": "^1.0.1", "passport-http-bearer": "^1.0.1",
"passport-ldapjs": "^1.0.2", "passport-ldapjs": "^1.0.2",
"progress": "^2.0.0",
"progress-stream": "^2.0.0",
"readline-sync": "^1.4.6", "readline-sync": "^1.4.6",
"redis": "^2.6.5", "redis": "^2.6.5",
"request": "^2.69.0", "request": "^2.69.0",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!