mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(commander) fillJSON
This commit is contained in:
parent
db889f9fa4
commit
e4faac2b49
1 changed files with 32 additions and 44 deletions
|
|
@ -104,58 +104,46 @@
|
|||
/**
|
||||
* Function fill JSON by file stats
|
||||
*
|
||||
* @param stats - object, contain file stats.
|
||||
* example {'1.txt': stat}
|
||||
*
|
||||
* @param files - array of files of current directory
|
||||
* @param params - { files, stats, path }
|
||||
*/
|
||||
function fillJSON(pParams) {
|
||||
var name, stat, mode, isDir, size, owner, modeStr,
|
||||
p, i, n, file, path, json, files,
|
||||
ret = Util.checkObjTrue(pParams, ['files', 'stats', 'path']);
|
||||
|
||||
if (ret) {
|
||||
p = pParams;
|
||||
n = p.files.length;
|
||||
|
||||
/* данные о файлах в формате JSON*/
|
||||
file = {};
|
||||
path = format.addSlashToEnd(p.path);
|
||||
function fillJSON(params) {
|
||||
var p = params,
|
||||
json = {
|
||||
path : path,
|
||||
path : '',
|
||||
files : []
|
||||
},
|
||||
files = json.files;
|
||||
|
||||
for (i = 0; i < n; i++ ) {
|
||||
name = p.files[i];
|
||||
};
|
||||
|
||||
Util.checkArgs(arguments, ['params']);
|
||||
|
||||
json.path = format.addSlashToEnd(p.path);
|
||||
json.files = p.files.map(function(name) {
|
||||
var file, isDir, size, owner, mode, modeStr,
|
||||
stat = p.stats[name];
|
||||
owner = stat.uid;
|
||||
|
||||
if (stat) {
|
||||
/* Переводим права доступа в 8-ричную систему */
|
||||
modeStr = Number(stat.mode).toString(8);
|
||||
mode = Number(modeStr);
|
||||
isDir = stat.isDirectory();
|
||||
size = isDir ? 'dir' : stat.size;
|
||||
}
|
||||
|
||||
file = {
|
||||
'name' : name,
|
||||
'size' : format.size(size),
|
||||
'owner' : owner,
|
||||
'mode' : format.permissions.symbolic(mode)
|
||||
};
|
||||
|
||||
files.push(file);
|
||||
|
||||
if (stat) {
|
||||
/* Переводим права доступа в 8-ричную систему */
|
||||
modeStr = Number(stat.mode).toString(8);
|
||||
mode = Number(modeStr);
|
||||
isDir = stat.isDirectory();
|
||||
size = isDir ? 'dir' : stat.size;
|
||||
}
|
||||
|
||||
json.files = changeOrder(files);
|
||||
file = {
|
||||
'name' : name,
|
||||
'size' : format.size(size),
|
||||
'owner' : owner,
|
||||
'mode' : format.permissions.symbolic(mode)
|
||||
};
|
||||
|
||||
changeUIDToName(json, function(error) {
|
||||
p.callback(error, json);
|
||||
});
|
||||
}
|
||||
return file;
|
||||
});
|
||||
|
||||
json.files = changeOrder(json.files);
|
||||
|
||||
changeUIDToName(json, function(error) {
|
||||
p.callback(error, json);
|
||||
});
|
||||
}
|
||||
|
||||
function changeUIDToName(json, callback) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue