From 07caeb5a80e8db3f9e8a31018328399af6282019 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 18 Feb 2014 10:30:18 -0500 Subject: [PATCH] refactor(cloudcmd) readIndex: add callback --- cloudcmd.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/cloudcmd.js b/cloudcmd.js index 6739ee68..064420ac 100644 --- a/cloudcmd.js +++ b/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, {