Commit 69bfad0e authored by Johannes Zellner's avatar Johannes Zellner

WIP

parent 6a1e16e6
......@@ -11,6 +11,8 @@ var superagent = require('superagent'),
readlineSync = require('readline-sync'),
safe = require('safetydance'),
async = require('async'),
ProgressBar = require('progress'),
ProgressStream = require('progress-stream'),
fs = require('fs'),
request = require('request'),
url = require('url'),
......@@ -138,18 +140,47 @@ function put(filePath, otherFilePaths, options) {
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;
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) {
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);
var readStream = fs.createReadStream(file);
var progress = new ProgressStream({ time: 50 });
progress.on('progress', function (p) { bar.update(p.percentage / 100); /* bar.tick(p.transferred - bar.curr); */ });
// 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);
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) {
if (error) {
console.log('Failed to put file.', error.message.red);
......
......@@ -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": {
"version": "1.1.2",
"from": "colors@>=1.1.2 <2.0.0",
......@@ -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": {
"version": "2.2.0",
"from": "debug@>=2.2.0 <3.0.0",
......@@ -806,6 +816,11 @@
"from": "inherits@2.0.3",
"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": {
"version": "1.26.0",
"from": "mime-db@>=1.26.0 <1.27.0",
......@@ -1031,6 +1046,26 @@
"from": "passport-strategy@>=1.0.0 <2.0.0",
"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": {
"version": "1.4.6",
"from": "readline-sync@latest",
......@@ -1450,11 +1485,21 @@
"from": "setprototypeof@1.0.2",
"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": {
"version": "1.3.1",
"from": "statuses@>=1.3.1 <2.0.0",
"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": {
"version": "1.8.1",
"from": "superagent@>=1.7.2 <2.0.0",
......@@ -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": {
"version": "1.8.3",
"from": "underscore@>=1.8.3 <2.0.0",
"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": {
"version": "3.0.1",
"from": "uuid@latest",
"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"
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment