mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-24 03:05:41 +00:00
removed html code from cloudfunc
This commit is contained in:
parent
4b480c1d8a
commit
dfa0d20b50
3 changed files with 75 additions and 111 deletions
81
cloudcmd.js
81
cloudcmd.js
|
|
@ -23,8 +23,14 @@
|
|||
|
||||
INDEX = HTMLDIR + 'index.html',
|
||||
CONFIG_PATH = JSONDIR + 'config.json',
|
||||
FS = CloudFunc.FS;
|
||||
CA = DIR + 'ssl/sub.class1.server.ca.pem',
|
||||
KEY = DIR + 'ssl/ssl.key',
|
||||
CERT = DIR + 'ssl/ssl.crt',
|
||||
TEMPLATEPATH= HTMLDIR + 'file.html',
|
||||
|
||||
Template,
|
||||
|
||||
FS = CloudFunc.FS;
|
||||
/* reinit main dir os if we on
|
||||
* Win32 should be backslashes */
|
||||
DIR = main.DIR;
|
||||
|
|
@ -181,27 +187,26 @@
|
|||
route : route
|
||||
};
|
||||
|
||||
if(Config.ssl){
|
||||
var CA = DIR + 'ssl/sub.class1.server.ca.pem',
|
||||
KEY = DIR + 'ssl/ssl.key',
|
||||
CERT = DIR + 'ssl/ssl.crt';
|
||||
|
||||
readFiles([ CA, KEY, CERT ], function(pErrors, pFiles){
|
||||
if(pErrors)
|
||||
Util.log(pErrors);
|
||||
else{
|
||||
var lFiles = [TEMPLATEPATH];
|
||||
|
||||
if(Config.ssl)
|
||||
lFiles.push(CA, KEY, CERT);
|
||||
|
||||
main.readFiles(lFiles, function(pErrors, pFiles){
|
||||
if(pErrors)
|
||||
Util.log(pErrors);
|
||||
else{
|
||||
Template = pFiles[TEMPLATEPATH].toString();
|
||||
if(Config.ssl)
|
||||
lParams.ssl = {
|
||||
ca : pFiles[CA],
|
||||
key : pFiles[KEY],
|
||||
cert : pFiles[CERT]
|
||||
};
|
||||
|
||||
server.start(lParams);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
server.start(lParams);
|
||||
|
||||
server.start(lParams);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
Util.log('read error: config.json');
|
||||
|
|
@ -301,7 +306,7 @@
|
|||
p.name = Minify.allowed.html ? Minify.getName(INDEX) : INDEX;
|
||||
fs.readFile(p.name, function(pError, pData){
|
||||
if(!pError){
|
||||
var lPanel = CloudFunc.buildFromJSON(pJSON),
|
||||
var lPanel = CloudFunc.buildFromJSON(pJSON, Template),
|
||||
lList = '<ul id=left class=panel>' + lPanel + '</ul>' +
|
||||
'<ul id=right class=panel>' + lPanel + '</ul>';
|
||||
|
||||
|
|
@ -321,46 +326,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
function readFiles(pFiles, pCallBack){
|
||||
var lDone = [],
|
||||
lFiles,
|
||||
lErrors,
|
||||
lReadedFiles = {},
|
||||
lDoneFunc = function (pParams){
|
||||
var lRet = Util.checkObj(pParams, ['error', 'data', 'params']);
|
||||
|
||||
if(lRet){
|
||||
lDone.pop();
|
||||
var p = pParams,
|
||||
lName = p.params;
|
||||
|
||||
if(p.error){
|
||||
if(!lErrors) lErrors = {};
|
||||
|
||||
lErrors[lName] = p.error;
|
||||
}
|
||||
else
|
||||
lReadedFiles[lName] = p.data;
|
||||
|
||||
if( !lDone.length )
|
||||
Util.exec(pCallBack, lErrors, lReadedFiles);
|
||||
}
|
||||
};
|
||||
|
||||
if( Util.isArray(pFiles) )
|
||||
lFiles = pFiles;
|
||||
else
|
||||
lFiles = [pFiles];
|
||||
|
||||
for(var i = 0, n = lFiles.length; i < n; i++){
|
||||
var lName = lFiles.pop();
|
||||
lDone.push(lName);
|
||||
|
||||
fs.readFile(lName, Util.call( lDoneFunc, lName ));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* function sets stdout to file log.txt */
|
||||
function writeLogsToFile(){
|
||||
|
|
|
|||
|
|
@ -348,27 +348,14 @@ var CloudFunc, exports, Util;
|
|||
lLink = FS + lDotDot;
|
||||
|
||||
/* Сохраняем путь к каталогу верхнего уровня*/
|
||||
|
||||
if(pTemplate)
|
||||
lFileTable += Util.render(pTemplate,{
|
||||
type : 'directory',
|
||||
link : lLink,
|
||||
name : '..',
|
||||
size : '<dir>',
|
||||
owner : '.',
|
||||
mode : ''
|
||||
});
|
||||
else
|
||||
lFileTable += '<li draggable class>' +
|
||||
'<span class="mini-icon directory"></span>' +
|
||||
'<span class=name>' +
|
||||
'<a href="' + lLink +
|
||||
'" draggable=true>' + "..</a>" +
|
||||
'</span>' +
|
||||
'<span class=size><dir></span>' +
|
||||
'<span class=owner>.</span>' +
|
||||
'<span class=mode></span>' +
|
||||
'</li>';
|
||||
lFileTable += Util.render(pTemplate,{
|
||||
type : 'directory',
|
||||
link : lLink,
|
||||
name : '..',
|
||||
size : '<dir>',
|
||||
owner : '.',
|
||||
mode : ''
|
||||
});
|
||||
}
|
||||
|
||||
for(var i = 1, n = files.length; i < n; i++){
|
||||
|
|
@ -385,44 +372,14 @@ var CloudFunc, exports, Util;
|
|||
lSize = CloudFunc.getShortSize( lFile.size );
|
||||
}
|
||||
|
||||
if(pTemplate)
|
||||
lFileTable += Util.render(pTemplate,{
|
||||
lFileTable += Util.render(pTemplate,{
|
||||
type : lType,
|
||||
link : FS + lPath + lFile.name,
|
||||
name : lFile.name,
|
||||
size : '<dir>',
|
||||
owner : lOwner,
|
||||
mode : lMode
|
||||
});
|
||||
else
|
||||
{
|
||||
lFileTable += '<li draggable class>';
|
||||
lFileTable += '<span draggable class="mini-icon ';
|
||||
|
||||
/* если папка - выводим другую иконку */
|
||||
lFileTable += lType + '">' +
|
||||
'</span>' +
|
||||
'<span draggable class=name>' +
|
||||
'<a href="' + FS + lPath + lFile.name +
|
||||
'"' +
|
||||
/* открываем файлы */
|
||||
/*в новой вкладке */
|
||||
(lFile.size === 'dir' ?
|
||||
'' : ' target="_blank"') +
|
||||
|
||||
' title="' + lFile.name +'"' +
|
||||
' draggable=true>' + lFile.name +
|
||||
"</a>" +
|
||||
'</span>';
|
||||
/* если папка - не выводим размер */
|
||||
lFileTable += '<span draggable class=size>' + lSize +
|
||||
'</span>' +
|
||||
'<span draggable class=owner>' + lOwner +
|
||||
'</span>' +
|
||||
'<span draggable class=mode>' + lMode +
|
||||
'</span>';
|
||||
lFileTable += '</li>';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return lFileTable;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@
|
|||
exports.sendResponse = sendResponse,
|
||||
exports.sendError = sendError,
|
||||
exports.redirect = redirect,
|
||||
exports.readFiles = readFiles,
|
||||
|
||||
exports.checkParams = checkParams,
|
||||
|
||||
|
|
@ -363,6 +364,47 @@
|
|||
return Util.checkObj(pParams, ['error', 'data', 'params']);
|
||||
}
|
||||
|
||||
function readFiles(pFiles, pCallBack){
|
||||
var lDone = [],
|
||||
lFiles,
|
||||
lErrors,
|
||||
lReadedFiles = {},
|
||||
lDoneFunc = function (pParams){
|
||||
var lRet = Util.checkObj(pParams, ['error', 'data', 'params']);
|
||||
|
||||
if(lRet){
|
||||
lDone.pop();
|
||||
var p = pParams,
|
||||
lName = p.params;
|
||||
|
||||
if(p.error){
|
||||
if(!lErrors) lErrors = {};
|
||||
|
||||
lErrors[lName] = p.error;
|
||||
}
|
||||
else{
|
||||
Util.log(lName + ' readed');
|
||||
lReadedFiles[lName] = p.data;
|
||||
}
|
||||
|
||||
if( !lDone.length )
|
||||
Util.exec(pCallBack, lErrors, lReadedFiles);
|
||||
}
|
||||
};
|
||||
|
||||
if( Util.isArray(pFiles) )
|
||||
lFiles = pFiles;
|
||||
else
|
||||
lFiles = [pFiles];
|
||||
|
||||
for(var i = 0, n = lFiles.length; i < n; i++){
|
||||
var lName = lFiles.pop();
|
||||
lDone.push(lName);
|
||||
|
||||
fs.readFile(lName, Util.call( lDoneFunc, lName ));
|
||||
}
|
||||
}
|
||||
|
||||
function checkParams(pParams, pAdditional){
|
||||
var lRet = Util.checkObjTrue( pParams, ['name', REQUEST, RESPONSE] );
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue