diff options
author | Johannes Zellner <johannes@nebulon.de> | 2015-09-08 15:05:13 +0200 |
---|---|---|
committer | Johannes Zellner <johannes@nebulon.de> | 2015-09-08 15:05:13 +0200 |
commit | 7bb99aff6337ee30a74a71f587c9a58eb5d24cb3 (patch) | |
tree | 98fcb22db6a93a7946ce453cff6d60cd6d4a2520 /cli | |
parent | b9ad5d9155a65125f83071b409b4193ee97ce9d8 (diff) | |
download | Surfer-7bb99aff6337ee30a74a71f587c9a58eb5d24cb3.tar.gz Surfer-7bb99aff6337ee30a74a71f587c9a58eb5d24cb3.tar.zst Surfer-7bb99aff6337ee30a74a71f587c9a58eb5d24cb3.zip |
Use 222 status code to indicate folder listing and use stdout only for data
Diffstat (limited to 'cli')
-rw-r--r-- | cli/actions.js | 37 | ||||
-rwxr-xr-x | cli/surfer.js | 2 |
2 files changed, 30 insertions, 9 deletions
diff --git a/cli/actions.js b/cli/actions.js index bdfc066..119b2ba 100644 --- a/cli/actions.js +++ b/cli/actions.js | |||
@@ -10,6 +10,7 @@ var superagent = require('superagent'), | |||
10 | readlineSync = require('readline-sync'), | 10 | readlineSync = require('readline-sync'), |
11 | async = require('async'), | 11 | async = require('async'), |
12 | fs = require('fs'), | 12 | fs = require('fs'), |
13 | request = require('request'), | ||
13 | url = require('url'), | 14 | url = require('url'), |
14 | path = require('path'); | 15 | path = require('path'); |
15 | 16 | ||
@@ -27,7 +28,7 @@ function checkConfig() { | |||
27 | 28 | ||
28 | gQuery = { username: config.username(), password: config.password() }; | 29 | gQuery = { username: config.username(), password: config.password() }; |
29 | 30 | ||
30 | console.log('Using server %s', config.server().yellow); | 31 | console.error('Using server %s', config.server().yellow); |
31 | } | 32 | } |
32 | 33 | ||
33 | function collectFiles(filesOrFolders) { | 34 | function collectFiles(filesOrFolders) { |
@@ -110,20 +111,40 @@ function put(filePath, otherFilePaths, options) { | |||
110 | function get(filePath) { | 111 | function get(filePath) { |
111 | checkConfig(); | 112 | checkConfig(); |
112 | 113 | ||
113 | superagent.get(config.server() + API + filePath).query(gQuery).end(function (error, result) { | 114 | // if no argument provided, fetch root |
114 | if (error && error.status === 401) return console.log('Login failed'); | 115 | filePath = filePath || '/'; |
115 | if (error && error.status === 404) return console.log('No such file or directory'); | 116 | |
116 | if (error) return console.log('Failed', result ? result.body : error); | 117 | request.get(config.server() + API + filePath, { qs: gQuery }, function (error, result, body) { |
118 | if (error) return console.error(error); | ||
119 | if (result.statusCode === 401) return console.log('Login failed'); | ||
120 | if (result.statusCode === 404) return console.log('No such file or directory'); | ||
117 | 121 | ||
118 | if (result.body && result.body.entries) { | 122 | // 222 indicates directory listing |
123 | if (result.statusCode === 222) { | ||
119 | console.log('Files:'); | 124 | console.log('Files:'); |
120 | result.body.entries.forEach(function (entry) { | 125 | JSON.parse(body).entries.forEach(function (entry) { |
121 | console.log('\t %s', entry); | 126 | console.log('\t %s', entry); |
122 | }); | 127 | }); |
123 | } else { | 128 | } else { |
124 | console.log(result.text); | 129 | console.log(body); |
125 | } | 130 | } |
126 | }); | 131 | }); |
132 | // var req = superagent.get(config.server() + API + filePath); | ||
133 | // req.query(gQuery); | ||
134 | // req.end(function (error, result) { | ||
135 | // if (error && error.status === 401) return console.log('Login failed'); | ||
136 | // if (error && error.status === 404) return console.log('No such file or directory'); | ||
137 | // if (error) return console.log('Failed', result ? result.body : error); | ||
138 | |||
139 | // if (result.body && result.body.entries) { | ||
140 | // console.log('Files:'); | ||
141 | // result.body.entries.forEach(function (entry) { | ||
142 | // console.log('\t %s', entry); | ||
143 | // }); | ||
144 | // } else { | ||
145 | // req.pipe(process.stdout); | ||
146 | // } | ||
147 | // }); | ||
127 | } | 148 | } |
128 | 149 | ||
129 | function del(filePath) { | 150 | function del(filePath) { |
diff --git a/cli/surfer.js b/cli/surfer.js index 15a88b3..ad37917 100755 --- a/cli/surfer.js +++ b/cli/surfer.js | |||
@@ -19,7 +19,7 @@ program.command('put <file> [files...]') | |||
19 | .description('Put a file') | 19 | .description('Put a file') |
20 | .action(actions.put); | 20 | .action(actions.put); |
21 | 21 | ||
22 | program.command('get') | 22 | program.command('get [file]') |
23 | .description('Get a file or directory') | 23 | .description('Get a file or directory') |
24 | .action(actions.get); | 24 | .action(actions.get); |
25 | 25 | ||