diff options
-rw-r--r-- | src/actions.js | 34 | ||||
-rwxr-xr-x | surfer.js | 25 |
2 files changed, 59 insertions, 0 deletions
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 @@ | |||
1 | 'use strict'; | ||
2 | |||
3 | exports.put = put; | ||
4 | exports.get = get; | ||
5 | exports.del = del; | ||
6 | |||
7 | var superagent = require('superagent'), | ||
8 | path = require('path'); | ||
9 | |||
10 | var server = 'http://localhost:3000/api/files/'; | ||
11 | |||
12 | function put(filePath) { | ||
13 | var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1); | ||
14 | superagent.put(server + relativeFilePath).attach('file', filePath).end(function (error, result) { | ||
15 | if (error) return console.log('Failed', result ? result.body : error); | ||
16 | console.log('Success', result.body); | ||
17 | }); | ||
18 | } | ||
19 | |||
20 | function get(filePath) { | ||
21 | var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1); | ||
22 | superagent.get(server + relativeFilePath).end(function (error, result) { | ||
23 | if (error) return console.log('Failed', result ? result.body : error); | ||
24 | console.log('Success', result.body); | ||
25 | }); | ||
26 | } | ||
27 | |||
28 | function del(filePath) { | ||
29 | var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1); | ||
30 | superagent.del(server + relativeFilePath).end(function (error, result) { | ||
31 | if (error) return console.log('Failed', result ? result.body : error); | ||
32 | console.log('Success', result.body); | ||
33 | }); | ||
34 | } | ||
diff --git a/surfer.js b/surfer.js new file mode 100755 index 0000000..703fc59 --- /dev/null +++ b/surfer.js | |||
@@ -0,0 +1,25 @@ | |||
1 | #!/usr/bin/env node | ||
2 | |||
3 | 'use strict'; | ||
4 | |||
5 | var program = require('commander'), | ||
6 | actions = require('./src/actions'); | ||
7 | |||
8 | // Allow self signed certs! | ||
9 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | ||
10 | |||
11 | program.version('0.1.0'); | ||
12 | |||
13 | program.command('put') | ||
14 | .description('Put a file') | ||
15 | .action(actions.put); | ||
16 | |||
17 | program.command('get') | ||
18 | .description('Get a file or directory') | ||
19 | .action(actions.get); | ||
20 | |||
21 | program.command('del') | ||
22 | .description('Delete a file') | ||
23 | .action(actions.del); | ||
24 | |||
25 | program.parse(process.argv); | ||