Commit 13080980 by Johannes Zellner

Send more folder listing details

1 parent 898fe7c8
Showing with 24 additions and 5 deletions
......@@ -153,9 +153,9 @@ function get(filePath) {
if (!files || files.entries.length === 0) {
console.log('No files on the server. Use %s to upload some.', 'surfer put <file>'.yellow);
} else {
console.log('Files:');
console.log('Entries:');
files.entries.forEach(function (entry) {
console.log('\t %s', entry);
console.log('\t %s', entry.isDirectory ? entry.filePath + '/' : entry.filePath);
});
}
} else {
......
'use strict';
var fs = require('fs'),
var async = require('async'),
fs = require('fs'),
path = require('path'),
rm = require('del'),
debug = require('debug')('files'),
......@@ -74,10 +75,28 @@ function get(req, res, next) {
debug('get', absoluteFilePath);
if (!result.isDirectory() && !result.isFile()) return next(new HttpError(500, 'unsupported type'));
if (result.isFile()) return res.sendFile(absoluteFilePath);
if (result.isDirectory()) return res.status(222).send({ entries: fs.readdirSync(absoluteFilePath) });
return next(new HttpError(500, 'unsupported type'));
async.map(fs.readdirSync(absoluteFilePath), function (filePath, callback) {
fs.stat(path.join(absoluteFilePath, filePath), function (error, result) {
if (error) return callback(error);
callback(null, {
isDirectory: result.isDirectory(),
isFile: result.isFile(),
atime: result.atime,
mtime: result.mtime,
ctime: result.ctime,
birthtime: result.birthtime,
size: result.size,
filePath: filePath
});
});
}, function (error, results) {
if (error) return next(new HttpError(500, error));
res.status(222).send({ entries: results });
});
});
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!