]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/commitdiff
Display uploaded URL
authorGirish Ramakrishnan <girish@forwardbias.in>
Fri, 27 Nov 2015 23:01:36 +0000 (15:01 -0800)
committerGirish Ramakrishnan <girish@forwardbias.in>
Fri, 27 Nov 2015 23:05:17 +0000 (15:05 -0800)
cli/actions.js

index 77672817d88f227e6f7c46a9887cf21c293b6eb2..e5b0c6ddc3a8f0a00324679967c2cade7bfc755a 100644 (file)
@@ -94,10 +94,15 @@ function put(filePath, otherFilePaths, options) {
 
     async.eachSeries(files, function (file, callback) {
         var relativeFilePath = path.resolve(file).slice(process.cwd().length + 1);
+        var destinationPath = (options.destination ? '/' + options.destination : '') + '/' + relativeFilePath;
+        console.log('Uploading file %s -> %s', relativeFilePath.cyan, destinationPath.cyan);
 
-        console.log('Uploading file %s -> %s', relativeFilePath.cyan, ((options.destination ? options.destination : '') + '/' + relativeFilePath).cyan);
+        superagent.put(config.server() + API + relativeFilePath).query(gQuery).attach('file', file).end(function (error, result) {
+            if (error) return callback(error);
+            if (result.statusCode !== 201) return callback(new Error('Error uploading file: ' + result.statusCode));
 
-        superagent.put(config.server() + API + relativeFilePath).query(gQuery).attach('file', file).end(callback);
+            console.log('Uploaded to ' + config.server() + destinationPath);
+        });
     }, function (error) {
         if (error) {
             console.log('Failed to put file.', error);