mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
refactor(cloudcmd) processContent
This commit is contained in:
parent
07caeb5a80
commit
8a5d9c9a36
1 changed files with 26 additions and 30 deletions
56
cloudcmd.js
56
cloudcmd.js
|
|
@ -227,7 +227,7 @@
|
|||
}
|
||||
|
||||
function sendContent(pParams) {
|
||||
var p, lRet = main.checkParams(pParams);
|
||||
var p, query, lRet = main.checkParams(pParams);
|
||||
|
||||
if (lRet) {
|
||||
p = pParams;
|
||||
|
|
@ -237,46 +237,42 @@
|
|||
if (error)
|
||||
main.sendError(pParams, error);
|
||||
else
|
||||
if (stat.isDirectory())
|
||||
processContent(pParams);
|
||||
else
|
||||
if (!stat.isDirectory())
|
||||
main.sendFile(pParams);
|
||||
else {
|
||||
query = main.getQuery(p.request),
|
||||
|
||||
processContent(p.name, query, function(name, error, data) {
|
||||
if (error)
|
||||
main.sendError(params, error);
|
||||
else {
|
||||
p.name = name;
|
||||
main.sendResponse(p, data, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return lRet;
|
||||
}
|
||||
|
||||
function processContent(params) {
|
||||
var p = params,
|
||||
ret = main.checkParams(params);
|
||||
|
||||
if (ret)
|
||||
main.commander.getDirContent(p.name, function(error, json) {
|
||||
var query, isJSON;
|
||||
function processContent(name, query, callback) {
|
||||
main.commander.getDirContent(name, function(error, json) {
|
||||
var data, name,
|
||||
isJSON = Util.isContainStr(query, 'json');
|
||||
|
||||
if (error)
|
||||
main.sendError(params, error);
|
||||
if (!isJSON && !error)
|
||||
readIndex(json, Util.retExec(callback, INDEX_PATH));
|
||||
else {
|
||||
query = main.getQuery(p.request);
|
||||
isJSON = Util.isContainStr(query, 'json');
|
||||
|
||||
if (!isJSON)
|
||||
readIndex(json, function(error, data) {
|
||||
p.name = INDEX_PATH;
|
||||
|
||||
if (error)
|
||||
main.sendError(p, error);
|
||||
else
|
||||
main.sendResponse(p, data, true);
|
||||
});
|
||||
else {
|
||||
p.data = Util.stringifyJSON(json);
|
||||
p.name +='.json';
|
||||
main.sendResponse(params, null, true);
|
||||
if (!error) {
|
||||
data = Util.stringifyJSON(json);
|
||||
name +='.json';
|
||||
}
|
||||
|
||||
Util.exec(callback, name, error, data);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function readIndex(json, callback) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue