mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(commander) readDir: params -> error, files, params
This commit is contained in:
parent
aa60da9c57
commit
7aea0483a6
1 changed files with 42 additions and 46 deletions
|
|
@ -22,13 +22,15 @@
|
|||
exports.getDirContent = function(path, callback) {
|
||||
var ret = Util.isString(path);
|
||||
|
||||
if (ret)
|
||||
fs.readdir(path, Util.call(readDir, {
|
||||
callback: callback,
|
||||
path : path
|
||||
}));
|
||||
else
|
||||
if (!ret)
|
||||
Util.exec(callback, "First parameter should be a string");
|
||||
else
|
||||
fs.readdir(path, function(error, files) {
|
||||
readDir(error, files, {
|
||||
callback : callback,
|
||||
path : path
|
||||
});
|
||||
});
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
|
@ -39,49 +41,43 @@
|
|||
* @param pError
|
||||
* @param pFiles
|
||||
*/
|
||||
function readDir(params) {
|
||||
function readDir(error, files, params) {
|
||||
var i, n, stats, filesData, fill, name, fileParams,
|
||||
p, c, files, dirPath,
|
||||
ret = checkParams(params);
|
||||
ret = ret && Util.checkObj(params.params, ['path']);
|
||||
|
||||
p = params,
|
||||
dirPath = getDirPath(p.path);
|
||||
|
||||
if (ret) {
|
||||
p = params,
|
||||
c = params.params,
|
||||
files = p.data,
|
||||
dirPath = getDirPath(c.path);
|
||||
if (error)
|
||||
Util.exec(p.callback, error.toString());
|
||||
else {
|
||||
/* Получаем информацию о файлах */
|
||||
n = files.length,
|
||||
stats = {},
|
||||
|
||||
if (!p.error && files) {
|
||||
/* Получаем информацию о файлах */
|
||||
n = files.length,
|
||||
stats = {},
|
||||
|
||||
filesData = {
|
||||
files : files,
|
||||
stats : stats,
|
||||
callback : c.callback,
|
||||
path : c.path
|
||||
},
|
||||
|
||||
fill = Util.retFunc(fillJSON, filesData);
|
||||
|
||||
if (n)
|
||||
for (i = 0; i < n; i++) {
|
||||
name = dirPath + files[i],
|
||||
|
||||
fileParams = {
|
||||
callback : fill,
|
||||
count : n,
|
||||
name : files[i],
|
||||
stats : stats,
|
||||
};
|
||||
|
||||
fs.stat(name, Util.call(getFilesStat, fileParams));
|
||||
}
|
||||
else
|
||||
fillJSON(filesData);
|
||||
} else
|
||||
Util.exec(c.callback, p.error.toString());
|
||||
filesData = {
|
||||
files : files,
|
||||
stats : stats,
|
||||
callback : p.callback,
|
||||
path : p.path
|
||||
},
|
||||
|
||||
fill = Util.retFunc(fillJSON, filesData);
|
||||
|
||||
if (n)
|
||||
for (i = 0; i < n; i++) {
|
||||
name = dirPath + files[i],
|
||||
|
||||
fileParams = {
|
||||
callback : fill,
|
||||
count : n,
|
||||
name : files[i],
|
||||
stats : stats,
|
||||
};
|
||||
|
||||
fs.stat(name, Util.call(getFilesStat, fileParams));
|
||||
}
|
||||
else
|
||||
fillJSON(filesData);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue