mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(cloudcmd) readIndex: add callback
This commit is contained in:
parent
2732f69733
commit
07caeb5a80
1 changed files with 16 additions and 13 deletions
29
cloudcmd.js
29
cloudcmd.js
|
|
@ -262,7 +262,14 @@
|
|||
isJSON = Util.isContainStr(query, 'json');
|
||||
|
||||
if (!isJSON)
|
||||
readIndex(json, params);
|
||||
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';
|
||||
|
|
@ -272,28 +279,24 @@
|
|||
});
|
||||
}
|
||||
|
||||
function readIndex(pJSON, params) {
|
||||
var p = params;
|
||||
|
||||
function readIndex(json, callback) {
|
||||
Util.ifExec(!Minify, function(params) {
|
||||
var name = params && params.name;
|
||||
|
||||
fs.readFile(name || INDEX_PATH, 'utf8', function(error, template) {
|
||||
var panel,
|
||||
var panel, data,
|
||||
config = main.config,
|
||||
minify = config.minify;
|
||||
|
||||
if (error)
|
||||
main.sendError(p, error);
|
||||
else {
|
||||
p.name = INDEX_PATH,
|
||||
panel = CloudFunc.buildFromJSON(pJSON, FileTemplate, PathTemplate, LinkTemplate),
|
||||
|
||||
main.sendResponse(p, indexProcessing({
|
||||
if (!error) {
|
||||
panel = CloudFunc.buildFromJSON(json, FileTemplate, PathTemplate, LinkTemplate),
|
||||
data = indexProcessing({
|
||||
panel : panel,
|
||||
data : template,
|
||||
}), true);
|
||||
});
|
||||
}
|
||||
|
||||
Util.exec(callback, error, data);
|
||||
});
|
||||
}, function(callback) {
|
||||
Minify.optimize(INDEX_PATH, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue