(function() { 'use strict'; var DIR = __dirname + '/', main = require(DIR + 'lib/server/main'), HTMLDIR = main.HTMLDIR, JSONDIR = main.JSONDIR, fs = main.fs, files = main.files, CloudFunc = main.cloudfunc, AppCache = main.appcache, Util = main.util, update = main.update, dir = main.dir, server = main.librequire('server'), Minify = main.minify, Config = main.config, CONFIG_PATH = JSONDIR + 'config.json', KEY = DIR + 'ssl/ssl.key', CERT = DIR + 'ssl/ssl.crt', HTML_FS_DIR = HTMLDIR + 'fs/', PATH_INDEX = HTML_FS_DIR + 'index.html', TMPL_PATH = [ 'file', 'panel', 'path', 'pathLink', 'link', ], Template = {}, FS = CloudFunc.FS; /* reinit main dir os if we on Win32 should be backslashes */ DIR = main.DIR; readConfig(init); /** * additional processing of index file */ function indexProcessing(options) { var keysPanel, left, right, LEFT = CloudFunc.PANEL_LEFT, RIGHT = CloudFunc.PANEL_RIGHT, data = options.data, panel = options.panel; if (!Config.appCache) data = Util.rmStr(data, [ /* min */ ' manifest=/cloudcmd.appcache', /* normal */ ' manifest="/cloudcmd.appcache"' ]); if (!Config.showKeysPanel) { keysPanel = '
' + name); p.name = main.HTMLDIR + name + '.html'; main.sendFile(p); } else if (isFS) { name = Util.rmStrOnce(name, CloudFunc.FS) || main.SLASH; getContent(name, function(error, data, isFile) { if (error) main.sendError(p, error); else if (isFile) { p.name = name; main.sendFile(p); } else readIndex(data, function(error, data) { var NOT_LOG = true; p.name = PATH_INDEX; if (error) main.sendError(error); else main.sendResponse(p, data, NOT_LOG); }); }); } } } function getContent(name, callback) { dir.isDir(name, function(error, isDir) { var getDirContent = main.commander.getDirContent, func = Util.exec.ret(callback); if (!error && isDir) getDirContent(name, callback); else func(error, null, !isDir); }); } function readIndex(json, callback) { var isMinify = Minify && Config.minify; Util.exec.if(!isMinify, function(error, params) { var name = params && params.name; fs.readFile(name || PATH_INDEX, 'utf8', function(error, template) { var panel, data; if (!error) { panel = CloudFunc.buildFromJSON({ data : json, template : Template }), data = indexProcessing({ panel : panel, data : template, }); } Util.exec(callback, error, data); }); }, function(callback) { Minify.optimize(PATH_INDEX, { callback : callback, returnName : true }); }); } /* function sets stdout to file log.txt */ function writeLogsToFile() { var stdout = process.stdout, writeFile = fs.createWriteStream('log.txt'), write = writeFile.write.bind(writeFile); stdout.write = write; } })();