Autors | SHA1 | Ziņojums | Datums |
---|---|---|---|
James Peret | 6516fa8161 | 7 gadi atpakaļ | |
James Peret | 82c7e3bed6 | 7 gadi atpakaļ | |
James Peret | 4f3a4974de | 7 gadi atpakaļ |
@@ -88,6 +88,33 @@ var buildFilename = function(path, filename){ |
||
88 | 88 |
return path + "/" + filename |
89 | 89 |
} |
90 | 90 |
|
91 |
+var list_folder = function(req, res){ |
|
92 |
+ var path = getPath(req); |
|
93 |
+ var file_type = ""; |
|
94 |
+ var parts; |
|
95 |
+ var extension; |
|
96 |
+ var folder_content = []; |
|
97 |
+ // Path is file or folder |
|
98 |
+ if(!isFile(req.params['file']) && req.params['file'] != undefined){ |
|
99 |
+ path = path + "./" + req.params['file'] + "/"; |
|
100 |
+ } |
|
101 |
+ if(path == "" || path == "undefined"){ |
|
102 |
+ path = "./"; |
|
103 |
+ } |
|
104 |
+ console.log("Listing folder: " + path); |
|
105 |
+ fs.readdir(path, function(err, files) { |
|
106 |
+ if(files != null){ |
|
107 |
+ files.forEach(function(file) { |
|
108 |
+ folder_content.push(file); |
|
109 |
+ }); |
|
110 |
+ res.json({ files: folder_content }); |
|
111 |
+ } else { |
|
112 |
+ res.json({ files: [] }); |
|
113 |
+ } |
|
114 |
+ |
|
115 |
+ }) |
|
116 |
+} |
|
117 |
+ |
|
91 | 118 |
var get_file = function(req, res){ |
92 | 119 |
|
93 | 120 |
var path = getPath(req); |
@@ -222,14 +249,21 @@ var url_paths = [ |
||
222 | 249 |
'/:folder_10/:folder_9/:folder_8/:folder_7/:folder_6/:folder_5/:folder_4/:folder_3/:folder_2/:folder_1/:file' |
223 | 250 |
] |
224 | 251 |
|
252 |
+// Get file |
|
225 | 253 |
for (var i = 0; i < url_paths.length; i++) { |
226 | 254 |
app.get(url_paths[i], function (req, res) { |
227 |
- get_file(req, res); |
|
255 |
+ if(req.query.list == "true"){ |
|
256 |
+ list_folder(req, res); |
|
257 |
+ } else { |
|
258 |
+ get_file(req, res); |
|
259 |
+ } |
|
228 | 260 |
}) |
229 | 261 |
} |
230 | 262 |
|
263 |
+// Write file content |
|
231 | 264 |
for (var i = 0; i < url_paths.length; i++) { |
232 | 265 |
app.post(url_paths[i], function (req, res) { |
266 |
+ console.log("Writing file: " + url_paths[i]); |
|
233 | 267 |
write_file(req, res); |
234 | 268 |
}) |
235 | 269 |
} |
@@ -1,6 +1,6 @@ |
||
1 | 1 |
{ |
2 | 2 |
"name": "@jamesperet/codex-server", |
3 |
- "version": "0.1.1", |
|
3 |
+ "version": "0.1.3", |
|
4 | 4 |
"description": "A node file server with super powers.", |
5 | 5 |
"main": "index.js", |
6 | 6 |
"scripts": { |