diff options
author | Johannes Zellner <johannes@nebulon.de> | 2016-03-01 13:14:45 +0100 |
---|---|---|
committer | Johannes Zellner <johannes@nebulon.de> | 2016-03-01 13:14:45 +0100 |
commit | 130809800e6e3fa33e5fc207dd6e1d963231f2a9 (patch) | |
tree | 38a2d85256be90a4ae59bc4429c9a3f41bce66b1 /src | |
parent | 898fe7c8bb0b04eea2e91d92f275c95713e8ec79 (diff) | |
download | Surfer-130809800e6e3fa33e5fc207dd6e1d963231f2a9.tar.gz Surfer-130809800e6e3fa33e5fc207dd6e1d963231f2a9.tar.zst Surfer-130809800e6e3fa33e5fc207dd6e1d963231f2a9.zip |
Send more folder listing details
Diffstat (limited to 'src')
-rw-r--r-- | src/files.js | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/files.js b/src/files.js index 2214449..520127d 100644 --- a/src/files.js +++ b/src/files.js | |||
@@ -1,6 +1,7 @@ | |||
1 | 'use strict'; | 1 | 'use strict'; |
2 | 2 | ||
3 | var fs = require('fs'), | 3 | var async = require('async'), |
4 | fs = require('fs'), | ||
4 | path = require('path'), | 5 | path = require('path'), |
5 | rm = require('del'), | 6 | rm = require('del'), |
6 | debug = require('debug')('files'), | 7 | debug = require('debug')('files'), |
@@ -74,10 +75,28 @@ function get(req, res, next) { | |||
74 | 75 | ||
75 | debug('get', absoluteFilePath); | 76 | debug('get', absoluteFilePath); |
76 | 77 | ||
78 | if (!result.isDirectory() && !result.isFile()) return next(new HttpError(500, 'unsupported type')); | ||
77 | if (result.isFile()) return res.sendFile(absoluteFilePath); | 79 | if (result.isFile()) return res.sendFile(absoluteFilePath); |
78 | if (result.isDirectory()) return res.status(222).send({ entries: fs.readdirSync(absoluteFilePath) }); | ||
79 | 80 | ||
80 | return next(new HttpError(500, 'unsupported type')); | 81 | async.map(fs.readdirSync(absoluteFilePath), function (filePath, callback) { |
82 | fs.stat(path.join(absoluteFilePath, filePath), function (error, result) { | ||
83 | if (error) return callback(error); | ||
84 | |||
85 | callback(null, { | ||
86 | isDirectory: result.isDirectory(), | ||
87 | isFile: result.isFile(), | ||
88 | atime: result.atime, | ||
89 | mtime: result.mtime, | ||
90 | ctime: result.ctime, | ||
91 | birthtime: result.birthtime, | ||
92 | size: result.size, | ||
93 | filePath: filePath | ||
94 | }); | ||
95 | }); | ||
96 | }, function (error, results) { | ||
97 | if (error) return next(new HttpError(500, error)); | ||
98 | res.status(222).send({ entries: results }); | ||
99 | }); | ||
81 | }); | 100 | }); |
82 | } | 101 | } |
83 | 102 | ||