refactor(cloudcmd) PREFIX -> prefix

This commit is contained in:
coderaiser 2018-10-29 18:44:10 +02:00
parent 6e65ad615b
commit 5e9db8eb3c
19 changed files with 53 additions and 50 deletions

View file

@ -58,9 +58,9 @@ function CloudCmdProto(DOM) {
const Files = DOM.Files;
this.log = log;
this.PREFIX = '';
this.prefix = '';
this.prefixSocket = '';
this.PREFIX_URL = '';
this.prefixURL = '';
this.DIRCLIENT = '/dist/';
this.DIRCLIENT_MODULES = this.DIRCLIENT + 'modules/';
@ -142,8 +142,8 @@ function CloudCmdProto(DOM) {
load.js(src, callback);
};
CloudCmd.PREFIX = prefix;
CloudCmd.PREFIX_URL = prefix + apiURL;
CloudCmd.prefix = prefix;
CloudCmd.prefixURL = prefix + apiURL;
CloudCmd.prefixSocket = config.prefixSocket;
CloudCmd.config = (key) => config[key];
@ -167,14 +167,14 @@ function CloudCmdProto(DOM) {
};
function loadStyle(callback) {
const prefix = CloudCmd.PREFIX;
const {prefix} = CloudCmd;
const name = prefix + '/dist/cloudcmd.common.css';
load.css(name, callback);
}
function loadPlugins(callback) {
const prefix = CloudCmd.PREFIX;
const {prefix} = CloudCmd;
const plugins = prefix + '/plugins.js';
load.js(plugins, callback);
@ -203,7 +203,7 @@ function CloudCmdProto(DOM) {
};
this.logOut = () => {
const url = CloudCmd.PREFIX + '/logout';
const url = CloudCmd.prefix + '/logout';
const error = () => document.location.reload();
DOM.Storage.clear();
@ -414,6 +414,7 @@ function CloudCmdProto(DOM) {
Files.get(names, (error, templFile, templPath, templLink, templPathLink) => {
const Dialog = DOM.Dialog;
const panel = panelParam || DOM.getPanel();
const {prefix} = CloudCmd;
const {
dir,
@ -434,7 +435,7 @@ function CloudCmdProto(DOM) {
order : options.order,
data : json,
id : panel.id,
prefix : CloudCmd.PREFIX,
prefix,
template : {
file : templFile,
path : templPath,

View file

@ -33,8 +33,8 @@ module.exports._CURRENT_FILE = CURRENT_FILE;
module.exports.setCurrentName = (name, current) => {
const Info = DOM.CurrentInfo;
const {link} = Info;
const {PREFIX} = CloudCmd;
const dir = PREFIX + FS + Info.dirPath;
const {prefix} = CloudCmd;
const dir = prefix + FS + Info.dirPath;
const encoded = encode(name);
link.title = encoded;
@ -84,7 +84,7 @@ module.exports.getCurrentDirPath = (panel = DOM.getPanel()) => {
module.exports.getCurrentPath = (currentFile) => {
const current = currentFile || DOM.getCurrentFile();
const element = DOM.getByTag('a', current)[0];
const prefix = CloudCmd.PREFIX;
const {prefix} = CloudCmd;
const path = element
.getAttribute('href')

View file

@ -182,7 +182,7 @@ test('current-file: isCurrentFile', (t) => {
function getCloudCmd({emit} = {}) {
return {
PREFIX: '',
prefix: '',
emit: emit || sinon.stub(),
};
}

View file

@ -27,7 +27,7 @@ module.exports = (items) => {
.replace(/\/$/, '');
const uploader = philip(entries, (type, name, data, i, n, callback) => {
const prefixURL = CloudCmd.PREFIX_URL;
const {prefixURL} = CloudCmd;
const full = prefixURL + FS + path + name;
let upload;

View file

@ -98,7 +98,7 @@ function showError(name) {
}
function getSystemFile(file, callback) {
const prefix = CloudCmd.PREFIX;
const {prefix} = CloudCmd;
if (!Promises[file])
Promises[file] = new Promise((success, error) => {

View file

@ -468,8 +468,9 @@ function CmdProto() {
*/
this.setHistory = (data, title, url) => {
const ret = window.history;
const {prefix} = CloudCmd;
url = CloudCmd.PREFIX + url;
url = prefix + url;
if (ret)
history.pushState(data, title, url);

View file

@ -14,7 +14,7 @@ const Files = require('./files');
const parallel = wraptile(load.parallel);
module.exports = (name, options, callback = options) => {
const {PREFIX, config} = CloudCmd;
const {prefix, config} = CloudCmd;
const o = options;
if (o.name && window[o.name])
@ -37,7 +37,7 @@ module.exports = (name, options, callback = options) => {
}
const localURL = local.map((url) => {
return PREFIX + url;
return prefix + url;
});
const remoteURL = remoteTmpls.map((tmpl) => {

View file

@ -176,9 +176,9 @@ function RESTful() {
function sendRequest(params) {
const p = params;
const prefixUrl = CloudCmd.PREFIX_URL;
const {prefixURL} = CloudCmd;
p.url = prefixUrl + p.url;
p.url = prefixURL + p.url;
p.url = encodeURI(p.url);
/*

View file

@ -49,8 +49,8 @@ function _loadFile(dir, n, file, callback) {
const name = file.name;
const path = dir + name;
const {PREFIX_URL} = CloudCmd;
const api = PREFIX_URL + FS;
const {prefixURL} = CloudCmd;
const api = prefixURL + FS;
const percent = (i, n, per = 100) => {
return Math.round(i * per / n);

View file

@ -180,7 +180,7 @@ function isNoCurrent(panel) {
function decodePath(path){
const url = CloudCmd.HOST;
const prefix = CloudCmd.PREFIX;
const {prefix} = CloudCmd;
const prefixReg = RegExp('^' + prefix + FS);
return decodeURI(path)

View file

@ -28,7 +28,7 @@ module.exports = function loadModule(params) {
CloudCmd[name] = () => {
exec(doBefore);
const prefix = CloudCmd.PREFIX;
const {prefix} = CloudCmd;
const pathFull = prefix + CloudCmd.DIRCLIENT_MODULES + path + '.js';
return loadJS(pathFull).then(async () => {

View file

@ -75,7 +75,7 @@ function initSocket() {
const href = getHost();
const {
prefixSocket,
PREFIX,
prefix,
} = CloudCmd;
const ONE_MINUTE = 60 * 1000;
@ -83,7 +83,7 @@ function initSocket() {
const socket = io.connect(href + prefixSocket + '/config', {
reconnectionAttempts: Infinity,
reconnectionDelay: ONE_MINUTE,
path: PREFIX + '/socket.io'
path: prefix + '/socket.io'
});
const save = (data) => {
@ -120,7 +120,7 @@ function show() {
if (!CloudCmd.config('configDialog'))
return;
const prefix = CloudCmd.PREFIX;
const {prefix} = CloudCmd;
const funcs = [
exec.with(Files.get, 'config-tmpl'),
exec.with(load.css, prefix + '/dist/config.css'),

View file

@ -124,8 +124,9 @@ function getDir(root, dir) {
function _rename(path, from, to, root) {
const dir = getDir(root, path);
const {prefix} = CloudCmd;
return fetch(CloudCmd.PREFIX + '/rename', {
return fetch(`${prefix}/rename`, {
method: 'put',
credentials: 'include',
body: JSON.stringify({

View file

@ -103,10 +103,10 @@ module.exports.hide = () => {
};
const loadFiles = async (element) => {
const socketPath = CloudCmd.PREFIX;
const {prefix} = CloudCmd;
const socketPath = prefix;
const {prefixSocket} = CloudCmd;
const prefix = socketPath + '/' + EditorName;
const url = prefix + '/' + EditorName + '.js';
const url = `${prefix}/${EditorName}/${EditorName}.js`;
time(Name + ' load');

View file

@ -53,7 +53,7 @@ module.exports.clear = () => {
};
function getPrefix() {
return CloudCmd.PREFIX + '/console';
return CloudCmd.prefix + '/console';
}
function getPrefixSocket() {
@ -91,7 +91,7 @@ const create = async () => {
env: getEnv(),
prefix: getPrefix(),
prefixSocket: getPrefixSocket(),
socketPath: CloudCmd.PREFIX,
socketPath: CloudCmd.prefix,
};
Element = createElement('div', {

View file

@ -252,7 +252,7 @@ function preDownload() {
function download(type) {
const TIME = 30 * 1000;
const prefixUr = CloudCmd.PREFIX_URL;
const {prefixURL} = CloudCmd;
const PACK = '/pack';
const date = Date.now();
const files = DOM.getActiveFiles();
@ -277,9 +277,9 @@ function download(type) {
let src;
if (isDir)
src = prefixUr + PACK + encodedPath + DOM.getPackerExt(type);
src = prefixURL + PACK + encodedPath + DOM.getPackerExt(type);
else
src = prefixUr + FS + encodedPath + '?download';
src = prefixURL + FS + encodedPath + '?download';
const element = createElement('iframe', {
id : id + '-' + date,

View file

@ -71,7 +71,7 @@ module.exports.init = promisify((callback) => {
if (!config('progress'))
return callback();
load(initOperations(CloudCmd.PREFIX, callback));
load(initOperations(CloudCmd.prefix, callback));
},
(callback) => {
Loaded = true;
@ -457,7 +457,7 @@ function message(msg, to, names) {
}
function load(callback) {
const prefix = CloudCmd.PREFIX;
const {prefix} = CloudCmd;
const file = `${prefix}/fileop/fileop.js`;
loadJS(file, (error) => {

View file

@ -28,12 +28,12 @@ const {config} = CloudCmd;
const loadAll = async () => {
const {
PREFIX,
prefix,
} = CloudCmd;
const prefix = getPrefix();
const js = `${prefix}/gritty.js`;
const css = `${PREFIX}/dist/terminal.css`;
const prefixGritty = getPrefix();
const js = `${prefixGritty}/gritty.js`;
const css = `${prefix}/dist/terminal.css`;
const [e] = await tryToCatch(loadParallel, [js, css]);
@ -64,7 +64,7 @@ function hide () {
}
function getPrefix() {
return CloudCmd.PREFIX + '/gritty';
return CloudCmd.prefix + '/gritty';
}
function getPrefixSocket() {
@ -84,7 +84,7 @@ function create() {
const options = {
env: getEnv(),
prefix: getPrefixSocket(),
socketPath: CloudCmd.PREFIX,
socketPath: CloudCmd.prefix,
fontFamily: 'Droid Sans Mono',
};

View file

@ -80,7 +80,7 @@ module.exports.init = async () => {
};
function show(data, options) {
const prefixUrl = CloudCmd.PREFIX_URL + FS;
const prefixURL = CloudCmd.prefixURL + FS;
if (Loading)
return;
@ -103,7 +103,7 @@ function show(data, options) {
Images.show.load();
const path = prefixUrl + Info.path;
const path = prefixURL + Info.path;
const type = getType(path);
switch(type) {
@ -111,7 +111,7 @@ function show(data, options) {
return viewFile();
case 'image':
return viewImage(path, prefixUrl);
return viewImage(path, prefixURL);
case 'media':
return viewMedia(path);
@ -185,10 +185,10 @@ function hide() {
modal.close();
}
function viewImage(href, prefixUrl) {
function viewImage(href, prefixURL) {
const makeTitle = (path) => {
return {
href: prefixUrl + path,
href: prefixURL + path,
title: encode(basename(path)),
};
};
@ -297,12 +297,12 @@ function check(src, callback) {
* @callback - executes, when everything loaded
*/
async function loadAll() {
const {PREFIX} = CloudCmd;
const {prefix} = CloudCmd;
time(Name + ' load');
Loading = true;
await loadCSS(PREFIX + '/dist/view.css');
await loadCSS(`${prefix}/dist/view.css`);
Loading = false;
}