X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=cli%2Factions.js;h=ea2a3a1d1e5b6280151bf3ea7076b31da54c902d;hb=e628921a338684a4bc3f196c5c39beba8b8f9b68;hp=8a8624e345d3354348c3834ed5b0bdbb818a3869;hpb=898fe7c8bb0b04eea2e91d92f275c95713e8ec79;p=perso%2FImmae%2FProjets%2FNodejs%2FSurfer.git diff --git a/cli/actions.js b/cli/actions.js index 8a8624e..ea2a3a1 100644 --- a/cli/actions.js +++ b/cli/actions.js @@ -118,9 +118,10 @@ function put(filePath, otherFilePaths, options) { var destinationPath = (destination ? '/' + destination : '') + '/' + relativeFilePath; console.log('Uploading file %s -> %s', relativeFilePath.cyan, destinationPath.cyan); - superagent.put(config.server() + API + destinationPath).query(gQuery).attach('file', file).end(function (error, result) { + 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); - if (result.statusCode !== 201) return callback(new Error('Error uploading file: ' + result.statusCode)); console.log('Uploaded to ' + config.server() + destinationPath); @@ -128,7 +129,7 @@ function put(filePath, otherFilePaths, options) { }); }, function (error) { if (error) { - console.log('Failed to put file.', error); + console.log('Failed to put file.', error.message.red); process.exit(1); } @@ -143,9 +144,9 @@ function get(filePath) { filePath = filePath || '/'; request.get(config.server() + API + filePath, { qs: gQuery }, function (error, result, body) { + if (result && result.statusCode === 401) return console.log('Login failed'); + if (result && result.statusCode === 404) return console.log('No such file or directory %s', filePath.yellow); if (error) return console.error(error); - if (result.statusCode === 401) return console.log('Login failed'); - if (result.statusCode === 404) return console.log('No such file or directory %s', filePath.yellow); // 222 indicates directory listing if (result.statusCode === 222) { @@ -153,9 +154,9 @@ function get(filePath) { if (!files || files.entries.length === 0) { console.log('No files on the server. Use %s to upload some.', 'surfer put '.yellow); } else { - console.log('Files:'); + console.log('Entries:'); files.entries.forEach(function (entry) { - console.log('\t %s', entry); + console.log('\t %s', entry.isDirectory ? entry.filePath + '/' : entry.filePath); }); } } else {