From 08b2ad7f716b3323ab8c168eb8a00a47fda03d66 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Sat, 27 Jun 2015 16:07:34 +0200 Subject: Add cli --- src/actions.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/actions.js (limited to 'src') diff --git a/src/actions.js b/src/actions.js new file mode 100644 index 0000000..33e47aa --- /dev/null +++ b/src/actions.js @@ -0,0 +1,34 @@ +'use strict'; + +exports.put = put; +exports.get = get; +exports.del = del; + +var superagent = require('superagent'), + path = require('path'); + +var server = 'http://localhost:3000/api/files/'; + +function put(filePath) { + var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1); + superagent.put(server + relativeFilePath).attach('file', filePath).end(function (error, result) { + if (error) return console.log('Failed', result ? result.body : error); + console.log('Success', result.body); + }); +} + +function get(filePath) { + var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1); + superagent.get(server + relativeFilePath).end(function (error, result) { + if (error) return console.log('Failed', result ? result.body : error); + console.log('Success', result.body); + }); +} + +function del(filePath) { + var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1); + superagent.del(server + relativeFilePath).end(function (error, result) { + if (error) return console.log('Failed', result ? result.body : error); + console.log('Success', result.body); + }); +} -- cgit v1.2.3