mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(config) improve speed: decrease config loading count
This commit is contained in:
parent
2769ac2ef5
commit
bbb8ca15c6
16 changed files with 290 additions and 358 deletions
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
function BufferProto(Util, DOM, CloudCmd) {
|
||||
var Storage = DOM.Storage,
|
||||
Files = DOM.Files,
|
||||
Info = DOM.CurrentInfo,
|
||||
json = Util.json,
|
||||
|
||||
|
|
@ -58,22 +57,13 @@
|
|||
});
|
||||
}
|
||||
|
||||
function isEnabled(callback) {
|
||||
Files.get('config', function(error, config) {
|
||||
if (error)
|
||||
showMessage(error);
|
||||
else
|
||||
callback(config.buffer);
|
||||
});
|
||||
}
|
||||
|
||||
function callIfEnabled(callback) {
|
||||
isEnabled(function(is) {
|
||||
if (is)
|
||||
callback();
|
||||
else
|
||||
showMessage('Buffer disabled in config!');
|
||||
});
|
||||
var is = CloudCmd.config('buffer');
|
||||
|
||||
if (is)
|
||||
return callback();
|
||||
|
||||
showMessage('Buffer disabled in config!');
|
||||
}
|
||||
|
||||
function copy() {
|
||||
|
|
|
|||
101
client/client.js
101
client/client.js
|
|
@ -157,44 +157,51 @@ var Util, DOM, CloudFunc, join;
|
|||
* выполняет весь функционал по
|
||||
* инициализации
|
||||
*/
|
||||
this.init = function(prefix) {
|
||||
var func = function() {
|
||||
Util.exec.series([
|
||||
initModules,
|
||||
baseInit,
|
||||
loadPlugins,
|
||||
function() {
|
||||
CloudCmd.route(location.hash);
|
||||
}
|
||||
]);
|
||||
},
|
||||
|
||||
funcBefore = function(callback) {
|
||||
var src = prefix + '/join:' + [
|
||||
CloudCmd.LIBDIRCLIENT + 'polyfill.js',
|
||||
'/modules/domtokenlist-shim/dist/domtokenlist.min.js',
|
||||
].join(':');
|
||||
|
||||
DOM.loadJquery(function() {
|
||||
DOM.load.js(src, callback);
|
||||
});
|
||||
};
|
||||
this.init = function(config) {
|
||||
var func = function() {
|
||||
Util.exec.series([
|
||||
initModules,
|
||||
baseInit,
|
||||
loadPlugins,
|
||||
function() {
|
||||
CloudCmd.route(location.hash);
|
||||
}
|
||||
]);
|
||||
};
|
||||
|
||||
CloudCmd.PREFIX = prefix;
|
||||
var funcBefore = function(callback) {
|
||||
var src = prefix + '/join:' + [
|
||||
CloudCmd.LIBDIRCLIENT + 'polyfill.js',
|
||||
'/modules/domtokenlist-shim/dist/domtokenlist.min.js',
|
||||
].join(':');
|
||||
|
||||
DOM.loadJquery(function() {
|
||||
DOM.load.js(src, callback);
|
||||
});
|
||||
};
|
||||
|
||||
var prefix = config.prefix;
|
||||
|
||||
CloudCmd.PREFIX = prefix;
|
||||
CloudCmd.PREFIX_URL = prefix + CloudFunc.apiURL;
|
||||
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
var options = {
|
||||
htmlDialogs: !error && config.htmlDialogs
|
||||
};
|
||||
|
||||
if (config.onePanelMode)
|
||||
CloudCmd.MIN_ONE_PANEL_WIDTH = Infinity;
|
||||
|
||||
if (error)
|
||||
CloudCmd.log(error);
|
||||
|
||||
DOM.Dialog = new DOM.Dialog(prefix, options);
|
||||
CloudCmd.config = function(key) {
|
||||
return config[key];
|
||||
};
|
||||
|
||||
CloudCmd._config = function(key, value) {
|
||||
/*
|
||||
* should be called from config.js only
|
||||
* after successful update on server
|
||||
*/
|
||||
config[key] = value;
|
||||
};
|
||||
|
||||
if (config.onePanelMode)
|
||||
CloudCmd.MIN_ONE_PANEL_WIDTH = Infinity;
|
||||
|
||||
DOM.Dialog = new DOM.Dialog(prefix, {
|
||||
htmlDialogs: config.htmlDialogs
|
||||
});
|
||||
|
||||
Util.exec.if(document.body.scrollIntoViewIfNeeded, func, funcBefore);
|
||||
|
|
@ -213,11 +220,11 @@ var Util, DOM, CloudFunc, join;
|
|||
if (!Array.isArray(urls))
|
||||
throw Error('urls should be array!');
|
||||
|
||||
urls = urls.map(function(url) {
|
||||
var noPrefixUrls = urls.map(function(url) {
|
||||
return url.replace(prefix, '');
|
||||
});
|
||||
|
||||
return prefix + join(urls);
|
||||
return prefix + join(noPrefixUrls);
|
||||
};
|
||||
|
||||
this.route = function(path) {
|
||||
|
|
@ -419,20 +426,12 @@ var Util, DOM, CloudFunc, join;
|
|||
|
||||
CloudCmd.log('reading dir: "' + path + '";');
|
||||
|
||||
Files.get('config', function(error, config) {
|
||||
var dirStorage,
|
||||
Dialog = DOM.Dialog;
|
||||
|
||||
if (error)
|
||||
Dialog.alert(TITLE, error);
|
||||
else
|
||||
dirStorage = config.dirStorage;
|
||||
|
||||
if (dirStorage)
|
||||
Storage.get(path, create);
|
||||
else
|
||||
create();
|
||||
});
|
||||
var dirStorage = CloudCmd.config(dirStorage);
|
||||
|
||||
if (!dirStorage)
|
||||
return create();
|
||||
|
||||
Storage.get(path, create);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ var CloudCmd;
|
|||
|
||||
CloudCmd = load;
|
||||
|
||||
function load(prefix) {
|
||||
prefix = prefix || '';
|
||||
function load(config) {
|
||||
var prefix = config.prefix || '';
|
||||
|
||||
var modules = '/modules/';
|
||||
var client = 'client/';
|
||||
|
|
@ -53,7 +53,7 @@ var CloudCmd;
|
|||
var urlFiles = getJoinURL(allFiles);
|
||||
|
||||
createScript(prefix + urlFiles, function() {
|
||||
CloudCmd.init(prefix);
|
||||
CloudCmd.init(config);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
108
client/config.js
108
client/config.js
|
|
@ -9,6 +9,7 @@ var CloudCmd, Util, DOM, io;
|
|||
CloudCmd.Config = ConfigProto;
|
||||
|
||||
function ConfigProto() {
|
||||
var config = CloudCmd.config;
|
||||
var Loading = true,
|
||||
Key = CloudCmd.Key,
|
||||
Dialog = DOM.Dialog,
|
||||
|
|
@ -51,61 +52,58 @@ var CloudCmd, Util, DOM, io;
|
|||
}
|
||||
|
||||
function initSocket(error) {
|
||||
var socket,
|
||||
href = getHost(),
|
||||
prefix = CloudCmd.PREFIX,
|
||||
var href = getHost();
|
||||
var prefix = CloudCmd.PREFIX,
|
||||
FIVE_SECONDS = 5000,
|
||||
save = function(data) {
|
||||
save = function(data) {
|
||||
onSave(data);
|
||||
socket.send(data);
|
||||
};
|
||||
|
||||
if (!error) {
|
||||
socket = io.connect(href + prefix + '/config', {
|
||||
'max reconnection attempts' : Math.pow(2, 32),
|
||||
'reconnection limit' : FIVE_SECONDS,
|
||||
path: prefix + '/socket.io'
|
||||
});
|
||||
|
||||
authCheck(socket);
|
||||
|
||||
socket.on('connect', function() {
|
||||
Config.save = save;
|
||||
});
|
||||
|
||||
socket.on('config', function(config) {
|
||||
DOM.Storage.setAllowed(config.localStorage);
|
||||
});
|
||||
|
||||
socket.on('message', function(data) {
|
||||
onSave(data);
|
||||
});
|
||||
|
||||
socket.on('log', function(msg) {
|
||||
CloudCmd.log(msg);
|
||||
});
|
||||
|
||||
socket.on('disconnect', function() {
|
||||
Config.save = saveHttp;
|
||||
});
|
||||
|
||||
socket.on('err', function(error) {
|
||||
Dialog.alert(TITLE, error);
|
||||
});
|
||||
}
|
||||
if (error)
|
||||
return;
|
||||
|
||||
var socket = io.connect(href + prefix + '/config', {
|
||||
'max reconnection attempts' : Math.pow(2, 32),
|
||||
'reconnection limit' : FIVE_SECONDS,
|
||||
path: prefix + '/socket.io'
|
||||
});
|
||||
|
||||
authCheck(socket);
|
||||
|
||||
socket.on('connect', function() {
|
||||
Config.save = save;
|
||||
});
|
||||
|
||||
socket.on('config', function(config) {
|
||||
DOM.Storage.setAllowed(config.localStorage);
|
||||
});
|
||||
|
||||
socket.on('message', function(data) {
|
||||
onSave(data);
|
||||
});
|
||||
|
||||
socket.on('log', function(msg) {
|
||||
CloudCmd.log(msg);
|
||||
});
|
||||
|
||||
socket.on('disconnect', function() {
|
||||
Config.save = saveHttp;
|
||||
});
|
||||
|
||||
socket.on('err', function(error) {
|
||||
Dialog.alert(TITLE, error);
|
||||
});
|
||||
}
|
||||
|
||||
function authCheck(socket) {
|
||||
Files.get('config', function(error, config) {
|
||||
if (error)
|
||||
return Dialog.alert(TITLE, error);
|
||||
|
||||
if (config.auth) {
|
||||
socket.emit('auth', config.username, config.password);
|
||||
|
||||
socket.on('reject', function() {
|
||||
Dialog.alert(TITLE, 'Wrong credentials!');
|
||||
});
|
||||
}
|
||||
if (!config('auth'))
|
||||
return;
|
||||
|
||||
socket.emit('auth', config('username'), config('password'));
|
||||
|
||||
socket.on('reject', function() {
|
||||
Dialog.alert(TITLE, 'Wrong credentials!');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -214,6 +212,7 @@ var CloudCmd, Util, DOM, io;
|
|||
Object.keys(obj).forEach(function(name) {
|
||||
var data = obj[name];
|
||||
|
||||
CloudCmd._config(name, data);
|
||||
input.setValue(name, data, Element);
|
||||
});
|
||||
|
||||
|
|
@ -296,15 +295,10 @@ var CloudCmd, Util, DOM, io;
|
|||
}
|
||||
}
|
||||
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
if (error)
|
||||
return Dialog.alert(TITLE, error);
|
||||
|
||||
if (!config.configDialog)
|
||||
return;
|
||||
|
||||
init();
|
||||
});
|
||||
if (!CloudCmd.config('configDialog'))
|
||||
return;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
})(CloudCmd, Util, DOM);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ var CloudCmd, Util, DOM, CloudFunc;
|
|||
|
||||
/* global rendy */
|
||||
/* global itype */
|
||||
/* global exec */
|
||||
|
||||
var DOMFunc = function() {},
|
||||
DOMProto,
|
||||
|
|
@ -293,11 +294,11 @@ var CloudCmd, Util, DOM, CloudFunc;
|
|||
if (o.name && window[o.name])
|
||||
callback();
|
||||
else
|
||||
Files.get(['config', 'modules'], function(error, config, modules) {
|
||||
Files.get('modules', function(error, modules) {
|
||||
var remoteTmpls, local, remote,
|
||||
load = DOM.load,
|
||||
prefix = CloudCmd.PREFIX,
|
||||
online = config.online && navigator.onLine,
|
||||
online = CloudCmd.config('online') && navigator.onLine,
|
||||
|
||||
remoteObj = Util.findObjByNameInArr(modules, 'remote'),
|
||||
module = Util.findObjByNameInArr(remoteObj, name),
|
||||
|
|
@ -1185,31 +1186,30 @@ var CloudCmd, Util, DOM, CloudFunc;
|
|||
*
|
||||
* @param name
|
||||
* @param data
|
||||
* @param hash
|
||||
* @param callback
|
||||
*/
|
||||
this.saveDataToStorage = function(name, data, hash, callback) {
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
var allowed = config.localStorage,
|
||||
isDir = DOM.isCurrentIsDir(),
|
||||
nameHash = name + '-hash',
|
||||
nameData = name + '-data';
|
||||
var allowed = CloudCmd.config('localStorage');
|
||||
var isDir = DOM.isCurrentIsDir();
|
||||
var nameHash = name + '-hash';
|
||||
var nameData = name + '-data';
|
||||
|
||||
if (!allowed || isDir)
|
||||
return Util.exec(callback);
|
||||
|
||||
Util.exec.if(hash, function() {
|
||||
var Storage = DOM.Storage;
|
||||
|
||||
if (!allowed || isDir)
|
||||
Util.exec(callback);
|
||||
else
|
||||
Util.exec.if(hash, function() {
|
||||
var Storage = DOM.Storage;
|
||||
|
||||
Storage.set(nameHash, hash);
|
||||
Storage.set(nameData, data);
|
||||
|
||||
Util.exec(callback, hash);
|
||||
}, function(callback) {
|
||||
DOM.loadCurrentHash(function(error, loadHash) {
|
||||
hash = loadHash;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
Storage.set(nameHash, hash);
|
||||
Storage.set(nameData, data);
|
||||
|
||||
Util.exec(callback, hash);
|
||||
}, function(callback) {
|
||||
DOM.loadCurrentHash(function(error, loadHash) {
|
||||
hash = loadHash;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -1221,32 +1221,22 @@ var CloudCmd, Util, DOM, CloudFunc;
|
|||
* @param callback
|
||||
*/
|
||||
this.getDataFromStorage = function(name, callback) {
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
var Storage = DOM.Storage,
|
||||
nameHash = name + '-hash',
|
||||
nameData = name + '-data',
|
||||
allowed = config.localStorage,
|
||||
isDir = DOM.isCurrentIsDir();
|
||||
|
||||
if (!allowed || isDir)
|
||||
Util.exec(callback);
|
||||
else {
|
||||
Util.exec.parallel([
|
||||
function(callback) {
|
||||
Storage.get(nameData, callback);
|
||||
},
|
||||
function(callback) {
|
||||
Storage.get(nameHash, callback);
|
||||
}
|
||||
], callback);
|
||||
}
|
||||
});
|
||||
var Storage = DOM.Storage;
|
||||
var nameHash = name + '-hash';
|
||||
var nameData = name + '-data';
|
||||
var allowed = CloudCmd.config('localStorage');
|
||||
var isDir = DOM.isCurrentIsDir();
|
||||
|
||||
if (!allowed || isDir)
|
||||
return Util.exec(callback);
|
||||
|
||||
Util.exec.parallel([
|
||||
exec.with(Storage.get, nameData, callback),
|
||||
exec.with(Storage.get, nameHash, callback),
|
||||
], callback);
|
||||
};
|
||||
|
||||
/** function getting FM
|
||||
* @param pPanel_o = {active: true}
|
||||
*/
|
||||
this.getFM = function() {
|
||||
this.getFM = function() {
|
||||
return this.getPanel().parentElement;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format;
|
|||
var Dialog = DOM.Dialog;
|
||||
var exec = Util.exec;
|
||||
var EditFile = this;
|
||||
var config = CloudCmd.config;
|
||||
|
||||
var Menu,
|
||||
|
||||
|
|
@ -88,17 +89,12 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format;
|
|||
}
|
||||
|
||||
function authCheck(spawn) {
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
if (error)
|
||||
return Dialog.alert(TITLE, error);
|
||||
|
||||
if (!config.auth)
|
||||
return;
|
||||
|
||||
spawn.emit('auth', config.username, config.password);
|
||||
spawn.on('reject', function() {
|
||||
Dialog.alert(TITLE, 'Wrong credentials!');
|
||||
});
|
||||
if (!config('auth'))
|
||||
return;
|
||||
|
||||
spawn.emit('auth', config('username'), config('password'));
|
||||
spawn.on('reject', function() {
|
||||
Dialog.alert(TITLE, 'Wrong credentials!');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,8 +96,9 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
|
|||
.split('\n');
|
||||
|
||||
var reject = Promise.reject.bind(Promise);
|
||||
var root = CloudCmd.config('root');
|
||||
|
||||
getRoot()
|
||||
Promise.resolve(root)
|
||||
.then(rename(dir, from, to))
|
||||
.then(function(res) {
|
||||
if (res.status === 404)
|
||||
|
|
@ -198,17 +199,6 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
|
|||
});
|
||||
}
|
||||
|
||||
function getRoot() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
if (error)
|
||||
return reject(error);
|
||||
|
||||
resolve(config.root);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function isChanged() {
|
||||
var editor = CloudCmd.Edit.getEditor();
|
||||
var msg = 'Apply new names?';
|
||||
|
|
|
|||
|
|
@ -10,16 +10,12 @@ var CloudCmd, Util, DOM, CloudFunc;
|
|||
function EditProto(callback) {
|
||||
var Name = 'Edit';
|
||||
var Loading = true;
|
||||
var EditorName = CloudCmd.config('editor');
|
||||
|
||||
var Dialog = DOM.Dialog,
|
||||
exec = Util.exec,
|
||||
Element,
|
||||
|
||||
EditorName = 'edward',
|
||||
var exec = Util.exec;
|
||||
var Element,
|
||||
editor,
|
||||
|
||||
TITLE = 'Edit',
|
||||
|
||||
ConfigView = {
|
||||
afterShow: function() {
|
||||
editor
|
||||
|
|
@ -40,7 +36,6 @@ var CloudCmd, Util, DOM, CloudFunc;
|
|||
|
||||
exec.series([
|
||||
CloudCmd.View,
|
||||
getConfig,
|
||||
function(callback) {
|
||||
loadFiles(element, callback);
|
||||
},
|
||||
|
|
@ -107,17 +102,6 @@ var CloudCmd, Util, DOM, CloudFunc;
|
|||
CloudCmd.View.hide();
|
||||
};
|
||||
|
||||
function getConfig(callback) {
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
if (error)
|
||||
Dialog.alert(TITLE, error);
|
||||
else if (config.editor)
|
||||
EditorName = config.editor;
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
function loadFiles(element, callback) {
|
||||
var prefix = CloudCmd.PREFIX;
|
||||
var prefixName = prefix + '/' + EditorName;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
/* global Util */
|
||||
/* global DOM */
|
||||
/* global Console */
|
||||
/* global exec */
|
||||
|
||||
(function(CloudCmd, Util, DOM) {
|
||||
'use strict';
|
||||
|
|
@ -9,21 +10,21 @@
|
|||
CloudCmd.Konsole = ConsoleProto;
|
||||
|
||||
function ConsoleProto() {
|
||||
var Name = 'Konsole',
|
||||
var config = CloudCmd.config;
|
||||
var Name = 'Konsole',
|
||||
TITLE = 'Console',
|
||||
|
||||
Element,
|
||||
Loaded,
|
||||
Images = DOM.Images,
|
||||
Dialog = DOM.Dialog,
|
||||
exec = Util.exec,
|
||||
|
||||
Konsole = this;
|
||||
|
||||
function init() {
|
||||
Images.show.load('top');
|
||||
|
||||
Util.exec.series([
|
||||
exec.series([
|
||||
CloudCmd.View,
|
||||
load,
|
||||
create,
|
||||
|
|
@ -68,7 +69,7 @@
|
|||
|
||||
Console(Element, options, function(spawn) {
|
||||
spawn.on('connect', exec.with(authCheck, spawn));
|
||||
Util.exec(callback);
|
||||
exec(callback);
|
||||
});
|
||||
|
||||
Console.addShortCuts({
|
||||
|
|
@ -83,17 +84,13 @@
|
|||
}
|
||||
|
||||
function authCheck(spawn) {
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
if (error)
|
||||
return Dialog.alert(TITLE, error);
|
||||
|
||||
if (config.auth) {
|
||||
spawn.emit('auth', config.username, config.password);
|
||||
|
||||
spawn.on('reject', function() {
|
||||
Dialog.alert(TITLE, 'Wrong credentials!');
|
||||
});
|
||||
}
|
||||
if (!config('auth'))
|
||||
return;
|
||||
|
||||
spawn.emit('auth', config('username'), config('password'));
|
||||
|
||||
spawn.on('reject', function() {
|
||||
Dialog.alert(TITLE, 'Wrong credentials!');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +99,7 @@
|
|||
CloudCmd.View.show(Element, {
|
||||
afterShow: function() {
|
||||
Console.focus();
|
||||
Util.exec(callback);
|
||||
exec(callback);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -117,22 +114,17 @@
|
|||
} else {
|
||||
Loaded = true;
|
||||
Util.timeEnd(Name + ' load');
|
||||
Util.exec(callback);
|
||||
exec(callback);
|
||||
}
|
||||
});
|
||||
|
||||
Util.time(Name + ' load');
|
||||
}
|
||||
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
if (error)
|
||||
return Dialog.alert(TITLE, error);
|
||||
|
||||
if (!config.console)
|
||||
return;
|
||||
|
||||
init();
|
||||
});
|
||||
if (!CloudCmd.config('console'))
|
||||
return;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
})(CloudCmd, Util, DOM);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
|
|||
CloudCmd.Menu = MenuProto;
|
||||
|
||||
function MenuProto(position) {
|
||||
var config = CloudCmd.config;
|
||||
var Buffer = DOM.Buffer,
|
||||
Info = DOM.CurrentInfo,
|
||||
Loading = true,
|
||||
|
|
@ -105,17 +106,6 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
|
|||
}
|
||||
}
|
||||
|
||||
function isAuth(callback) {
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
var is = config.auth;
|
||||
|
||||
if (error)
|
||||
DOM.alert(TITLE, error);
|
||||
|
||||
callback(is);
|
||||
});
|
||||
}
|
||||
|
||||
function getOptions(notFile) {
|
||||
var name, func, options;
|
||||
|
||||
|
|
@ -166,45 +156,44 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
|
|||
}
|
||||
|
||||
function loadFileMenuData(callback) {
|
||||
isAuth(function(is) {
|
||||
var show = function(name) {
|
||||
CloudCmd[name].show();
|
||||
var is = CloudCmd.config('auth');
|
||||
var show = function(name) {
|
||||
CloudCmd[name].show();
|
||||
},
|
||||
Dialog = DOM.Dialog,
|
||||
menuData = getMenuData(is),
|
||||
menu = {
|
||||
'View' : curry(show, 'View'),
|
||||
'Edit' : curry(show, 'Edit'),
|
||||
'Rename' : function() {
|
||||
setTimeout(DOM.renameCurrent, 100);
|
||||
},
|
||||
Dialog = DOM.Dialog,
|
||||
menuData = getMenuData(is),
|
||||
menu = {
|
||||
'View' : curry(show, 'View'),
|
||||
'Edit' : curry(show, 'Edit'),
|
||||
'Rename' : function() {
|
||||
setTimeout(DOM.renameCurrent, 100);
|
||||
},
|
||||
'Delete' : function() {
|
||||
CloudCmd.Operation.show('delete');
|
||||
},
|
||||
'Pack' : function() {
|
||||
CloudCmd.Operation.show('pack');
|
||||
},
|
||||
'Extract' : function() {
|
||||
CloudCmd.Operation.show('extract');
|
||||
},
|
||||
'Download' : preDownload,
|
||||
'Upload To Cloud': curry(uploadTo, 'Cloud'),
|
||||
'Cut' : function() {
|
||||
isCurrent(Buffer.cut, function() {
|
||||
Dialog.alert.noFiles(TITLE);
|
||||
});
|
||||
},
|
||||
'Copy' : function() {
|
||||
isCurrent(Buffer.copy, function() {
|
||||
Dialog.alert.noFiles(TITLE);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
Util.copyObj(menu, menuData);
|
||||
|
||||
callback(is, menu);
|
||||
});
|
||||
'Delete' : function() {
|
||||
CloudCmd.Operation.show('delete');
|
||||
},
|
||||
'Pack' : function() {
|
||||
CloudCmd.Operation.show('pack');
|
||||
},
|
||||
'Extract' : function() {
|
||||
CloudCmd.Operation.show('extract');
|
||||
},
|
||||
'Download' : preDownload,
|
||||
'Upload To Cloud': curry(uploadTo, 'Cloud'),
|
||||
'Cut' : function() {
|
||||
isCurrent(Buffer.cut, function() {
|
||||
Dialog.alert.noFiles(TITLE);
|
||||
});
|
||||
},
|
||||
'Copy' : function() {
|
||||
isCurrent(Buffer.copy, function() {
|
||||
Dialog.alert.noFiles(TITLE);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
Util.copyObj(menu, menuData);
|
||||
|
||||
callback(is, menu);
|
||||
}
|
||||
|
||||
function isCurrent(yesFn, noFn) {
|
||||
|
|
@ -282,9 +271,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
|
|||
}
|
||||
|
||||
function preDownload() {
|
||||
DOM.Files.get('config', function(e, config) {
|
||||
download(config && config.packer);
|
||||
});
|
||||
download(config('packer'));
|
||||
}
|
||||
|
||||
function download(type) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
/* global CloudCmd */
|
||||
var Util, DOM;
|
||||
|
||||
(function(Util, DOM) {
|
||||
'use strict';
|
||||
|
||||
var Notify = Util.extendProto(NotifyProto),
|
||||
DOMProto = Object.getPrototypeOf(DOM);
|
||||
var config = CloudCmd.config;
|
||||
var Notify = Util.extendProto(NotifyProto);
|
||||
var DOMProto = Object.getPrototypeOf(DOM);
|
||||
|
||||
Util.extend(DOMProto, {
|
||||
Notify: Notify
|
||||
|
|
@ -26,20 +28,18 @@ var Util, DOM;
|
|||
});
|
||||
|
||||
this.send = function(msg) {
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
var notify,
|
||||
notifications = config.notifications,
|
||||
focus = window.focus.bind(window),
|
||||
granted = Notify.check();
|
||||
|
||||
if (notifications && granted && Show) {
|
||||
notify = new Notification(msg, {
|
||||
icon: '/img/favicon/favicon-notify.png'
|
||||
});
|
||||
|
||||
Events.addClick(notify, focus);
|
||||
}
|
||||
});
|
||||
var notify,
|
||||
notifications = config('notifications'),
|
||||
focus = window.focus.bind(window),
|
||||
granted = Notify.check();
|
||||
|
||||
if (notifications && granted && Show) {
|
||||
notify = new Notification(msg, {
|
||||
icon: '/img/favicon/favicon-notify.png'
|
||||
});
|
||||
|
||||
Events.addClick(notify, focus);
|
||||
}
|
||||
};
|
||||
|
||||
this.check = function () {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
function OperationProto(operation, data) {
|
||||
var Name = 'Operation',
|
||||
TITLE = CloudCmd.TITLE,
|
||||
config = CloudCmd.config,
|
||||
Loaded,
|
||||
RESTful = DOM.RESTful,
|
||||
|
||||
|
|
@ -40,18 +41,12 @@
|
|||
Util.exec.series([
|
||||
DOM.loadSocket,
|
||||
function(callback) {
|
||||
var Files = DOM.Files;
|
||||
if (config('progress'))
|
||||
load(function(callback) {
|
||||
create(CloudCmd.PREFIX, callback);
|
||||
});
|
||||
|
||||
Files.get('config', function(error, config) {
|
||||
if (error)
|
||||
Dialog.alert('Config', error);
|
||||
else if (config.progress)
|
||||
load(function(callback) {
|
||||
create(CloudCmd.PREFIX, callback);
|
||||
});
|
||||
|
||||
callback();
|
||||
});
|
||||
callback();
|
||||
},
|
||||
function() {
|
||||
Loaded = true;
|
||||
|
|
@ -62,21 +57,15 @@
|
|||
}
|
||||
|
||||
function authCheck(spawn, ok) {
|
||||
DOM.Files.get('config', function(error, config) {
|
||||
if (error)
|
||||
return Dialog.alert(TITLE, error);
|
||||
if (!config('auth'))
|
||||
return ok();
|
||||
|
||||
if (!config.auth) {
|
||||
ok();
|
||||
} else {
|
||||
spawn.on('accept', ok);
|
||||
spawn.on('reject', function() {
|
||||
Dialog.alert(TITLE, 'Wrong credentials!');
|
||||
});
|
||||
|
||||
spawn.emit('auth', config.username, config.password);
|
||||
}
|
||||
spawn.on('accept', ok);
|
||||
spawn.on('reject', function() {
|
||||
Dialog.alert(TITLE, 'Wrong credentials!');
|
||||
});
|
||||
|
||||
spawn.emit('auth', config('username'), config('password'));
|
||||
}
|
||||
|
||||
function _initSpero(prefix, fn) {
|
||||
|
|
@ -142,15 +131,10 @@
|
|||
}
|
||||
|
||||
function _initPacker(prefix, fn) {
|
||||
DOM.Files.get('config', function(e, config) {
|
||||
if (e)
|
||||
return CloudCmd.log(e);
|
||||
if (config('packer') === 'zip')
|
||||
return _setPacker(prefix, 'salam', salam, fn);
|
||||
|
||||
if (config.packer === 'zip')
|
||||
return _setPacker(prefix, 'salam', salam, fn);
|
||||
|
||||
_setPacker(prefix, 'ishtar', ishtar, fn);
|
||||
});
|
||||
_setPacker(prefix, 'ishtar', ishtar, fn);
|
||||
}
|
||||
|
||||
function create(prefix) {
|
||||
|
|
@ -264,17 +248,13 @@
|
|||
};
|
||||
|
||||
this.pack = function() {
|
||||
DOM.Files.get('config', function(e, config) {
|
||||
var zip = config && config.packer === 'zip';
|
||||
twopack('pack', zip ? 'zip' : 'tar');
|
||||
});
|
||||
var isZip = config('packer') === 'zip';
|
||||
twopack('pack', isZip ? 'zip' : 'tar');
|
||||
};
|
||||
|
||||
this.extract = function() {
|
||||
DOM.Files.get('config', function(e, config) {
|
||||
var zip = config && config.packer === 'zip';
|
||||
twopack('extract', zip ? 'zip' : 'tar');
|
||||
});
|
||||
var isZip = config('packer') === 'zip';
|
||||
twopack('extract', isZip ? 'zip' : 'tar');
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
</div>
|
||||
<script src="{{ prefix }}/cloudcmd.js"></script>
|
||||
<script>
|
||||
CloudCmd('{{ prefix }}');
|
||||
CloudCmd({{ config }});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -65,7 +65,10 @@ module.exports.listen = (socket, authCheck) => {
|
|||
function manage(key, value) {
|
||||
if (!key)
|
||||
return;
|
||||
|
||||
|
||||
if (key === '*')
|
||||
return config;
|
||||
|
||||
if (value === undefined)
|
||||
return config[key];
|
||||
|
||||
|
|
|
|||
|
|
@ -56,10 +56,6 @@ module.exports = (req, res, next) => {
|
|||
* additional processing of index file
|
||||
*/
|
||||
function indexProcessing(options) {
|
||||
let from;
|
||||
let to;
|
||||
let left = '';
|
||||
let right = '';
|
||||
const keysPanel = '<div id="js-keyspanel" class="{{ className }}';
|
||||
const isOnePanel = config('onePanelMode');
|
||||
const noConfig = !config('configDialog');
|
||||
|
|
@ -68,6 +64,8 @@ function indexProcessing(options) {
|
|||
|
||||
let data = options.data;
|
||||
|
||||
let from;
|
||||
let to;
|
||||
if (!config('showKeysPanel')) {
|
||||
from = rendy(keysPanel, {
|
||||
className: 'keyspanel'
|
||||
|
|
@ -93,12 +91,13 @@ function indexProcessing(options) {
|
|||
data = data
|
||||
.replace('icon-console', 'icon-console none');
|
||||
|
||||
left = rendy(Template.panel, {
|
||||
let left = rendy(Template.panel, {
|
||||
side : 'left',
|
||||
content : panel,
|
||||
className : !isOnePanel ? '' : 'panel-single'
|
||||
});
|
||||
|
||||
let right = '';
|
||||
if (!isOnePanel)
|
||||
right = rendy(Template.panel, {
|
||||
side : 'right',
|
||||
|
|
@ -110,6 +109,7 @@ function indexProcessing(options) {
|
|||
title: CloudFunc.getTitle(),
|
||||
fm: left + right,
|
||||
prefix: prefix(),
|
||||
config: JSON.stringify(config('*')),
|
||||
css: CSS_URL
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,25 @@
|
|||
'use strict';
|
||||
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
const test = require('tape');
|
||||
const readjson = require('readjson');
|
||||
|
||||
const root = '../../';
|
||||
const config = require(root + 'server/config');
|
||||
const dir = root + 'server/';
|
||||
const config = require(dir + 'config');
|
||||
|
||||
const pathConfig = path.join(os.homedir(), '.cloudcmd.json');
|
||||
const localConfig = path.join(__dirname, '..', '..', 'json', 'config.json');
|
||||
|
||||
const clean = (name) => {
|
||||
delete require.cache[require.resolve(name)];
|
||||
};
|
||||
|
||||
function readConfig() {
|
||||
return readjson.sync.try(pathConfig) || require(localConfig);
|
||||
}
|
||||
|
||||
const before = require('../before');
|
||||
|
||||
|
|
@ -35,3 +52,13 @@ test('config: manage: get', (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
test('config: manage: get: *', (t) => {
|
||||
clean(dir + 'config');
|
||||
|
||||
const config = require(dir + 'config');
|
||||
const data = config('*');
|
||||
|
||||
t.deepEqual(data, readConfig(), 'should return config data');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue