diff --git a/client/client.js b/client/client.js index 49f19d1a..75c56d5e 100644 --- a/client/client.js +++ b/client/client.js @@ -4,11 +4,17 @@ const itype = require('itype/legacy'); const rendy = require('rendy'); const Images = require('./dom/images'); -/* global Util, DOM, CloudFunc, join */ +const { + apiURL, + formatMsg, + buildFromJSON, +} = require('../common/cloudfunc'); -module.exports = new CloudCmdProto(Util, DOM, CloudFunc); +/* global Util, DOM, join */ -function CloudCmdProto(Util, DOM, CloudFunc) { +module.exports = new CloudCmdProto(Util, DOM); + +function CloudCmdProto(Util, DOM) { let Key; let Debug; let Listeners; @@ -187,7 +193,7 @@ function CloudCmdProto(Util, DOM, CloudFunc) { }; CloudCmd.PREFIX = prefix; - CloudCmd.PREFIX_URL = prefix + CloudFunc.apiURL; + CloudCmd.PREFIX_URL = prefix + apiURL; CloudCmd.config = (key) => config[key]; CloudCmd._config = (key, value) => { @@ -239,7 +245,7 @@ function CloudCmdProto(Util, DOM, CloudFunc) { const current = DOM.getCurrentByName(file); if (file && !current) { - const msg = CloudFunc.formatMsg('set current file', file, 'error'); + const msg = formatMsg('set current file', file, 'error'); CloudCmd.log(msg); return; } @@ -476,7 +482,7 @@ function CloudCmdProto(Util, DOM, CloudFunc) { while (i--) panel.removeChild(panel.lastChild); - panel.innerHTML = CloudFunc.buildFromJSON({ + panel.innerHTML = buildFromJSON({ sort : options.sort, order : options.order, data : json, diff --git a/client/dom/directory.js b/client/dom/directory.js index f591f94a..dbfe929f 100644 --- a/client/dom/directory.js +++ b/client/dom/directory.js @@ -1,10 +1,10 @@ /* global CloudCmd */ -/* global CloudFunc */ /* global DOM */ 'use strict'; const Images = require('./images'); +const {FS} = require('../../common/cloudfunc'); module.exports = (items) => { const Info = DOM.CurrentInfo; @@ -35,7 +35,6 @@ module.exports = (items) => { const uploader = window.philip(entries, (type, name, data, i, n, callback) => { const prefixURL = CloudCmd.PREFIX_URL; - const FS = CloudFunc.FS; const full = prefixURL + FS + path + name; let upload; diff --git a/client/dom/index.js b/client/dom/index.js index 4254e4c4..20644e8a 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -1,5 +1,4 @@ /* global CloudCmd */ -/* global CloudFunc */ 'use strict'; @@ -9,6 +8,12 @@ const exec = require('execon'); const jonny = require('jonny'); const Util = require('../../common/util'); +const { + getTitle, + FS, + Entity, +} = require('../../common/cloudfunc'); + const DOMFunc = function() {}; const DOMTree = Util.extendProto(DOMTreeProto); @@ -283,7 +288,6 @@ function CmdProto() { const name = file.name; const path = dir + name; const prefixURL = CloudCmd.PREFIX_URL; - const FS = CloudFunc.FS; const api = prefixURL + FS; const percent = (i, n, per = 100) => { @@ -662,7 +666,6 @@ function CmdProto() { this.setCurrentFile = function(currentFile, options) { var path, pathWas, title, o = options, - FS = CloudFunc.FS, CENTER = true, currentFileWas = this.getCurrentFile(); @@ -677,7 +680,7 @@ function CmdProto() { path = DOM.getCurrentDirPath(); if (path !== pathWas) { - title = CloudFunc.getTitle(path); + title = getTitle(path); this.setTitle(title); /* history could be present @@ -938,14 +941,12 @@ function CmdProto() { * * @param currentFile - current file by default */ - this.getCurrentPath = function(currentFile) { - var current = currentFile || DOM.getCurrentFile(); - var element = DOM.getByTag('a', current)[0]; - var prefix = CloudCmd.PREFIX; - var fs = CloudFunc.FS; - - var path = element.getAttribute('href') - .replace(RegExp('^' + prefix + fs), ''); + this.getCurrentPath = (currentFile) => { + const current = currentFile || DOM.getCurrentFile(); + const element = DOM.getByTag('a', current)[0]; + const prefix = CloudCmd.PREFIX; + const path = element.getAttribute('href') + .replace(RegExp('^' + prefix + FS), ''); return path; }; @@ -1008,12 +1009,11 @@ function CmdProto() { this.setCurrentName = function(name, current) { var Info = CurrentInfo, link = Info.link, - FS = CloudFunc.FS, PREFIX = CloudCmd.PREFIX, dir = PREFIX + FS + Info.dirPath; link.title = name; - link.innerHTML = CloudFunc.Entity.encode(name); + link.innerHTML = Entity.encode(name); link.href = dir + name; current.setAttribute('data-name', 'js-file-' + name); diff --git a/client/dom/rest.js b/client/dom/rest.js index 7cca7a6b..bb4d9e35 100644 --- a/client/dom/rest.js +++ b/client/dom/rest.js @@ -1,8 +1,10 @@ 'use strict'; +/* global CloudCmd, DOM */ + const itype = require('itype/legacy'); -/* global CloudFunc, CloudCmd, DOM */ +const {FS} = require('../../common/cloudfunc'); module.exports = new RESTful(); @@ -20,7 +22,7 @@ function RESTful() { sendRequest({ method : 'DELETE', - url : CloudFunc.FS + url, + url : FS + url, data, callback, imgPosition : { top: !!data } @@ -37,7 +39,7 @@ function RESTful() { sendRequest({ method : 'PATCH', - url : CloudFunc.FS + url, + url : FS + url, data : data, callback : callback, imgPosition : { top: true } @@ -54,7 +56,7 @@ function RESTful() { sendRequest({ method : 'PUT', - url : CloudFunc.FS + url, + url : FS + url, data : data, callback : callback, imgPosition : { top: true } @@ -75,7 +77,7 @@ function RESTful() { sendRequest({ method: 'GET', - url: CloudFunc.FS + url, + url: FS + url, callback: callback, notLog: notLog, dataType: dataType diff --git a/client/listeners.js b/client/listeners.js index 79059365..a5f235ff 100644 --- a/client/listeners.js +++ b/client/listeners.js @@ -1,10 +1,15 @@ -/* global DOM, CloudFunc, CloudCmd */ +/* global DOM, CloudCmd */ 'use strict'; const exec = require('execon'); const itype = require('itype/legacy'); +const { + FS, + apiURL +} = require('../common/cloudfunc'); + module.exports.init = () => { contextMenu(); dragndrop(); @@ -142,7 +147,6 @@ function isNoCurrent(panel) { function onPathElementClick(panel, event) { let link, href, url, noCurrent; - const fs = CloudFunc.FS; const prefix = CloudCmd.PREFIX; const element = event.target; const attr = element.getAttribute('data-name'); @@ -172,7 +176,7 @@ function onPathElementClick(panel, event) { */ link = link.replace('%%', '%25%'); link = decodeURI(link); - link = link.replace(RegExp('^' + prefix + fs), '') || '/'; + link = link.replace(RegExp('^' + prefix + FS), '') || '/'; noCurrent = isNoCurrent(panel); @@ -267,7 +271,6 @@ function onTouch(event) { * in Chrome (HTML5) */ function onDragStart(event) { - const apiURL = CloudFunc.apiURL; const element = getLIElement(event.target); const isDir = Info.isDir; let link = DOM.getCurrentLink(element); @@ -448,7 +451,7 @@ function unload() { function pop() { Events.add('popstate', (event) => { const path = event.state || '' - .replace(CloudFunc.FS, ''); + .replace(FS, ''); if (!path) return CloudCmd.route(location.hash); diff --git a/client/modules/edit.js b/client/modules/edit.js index b48f7eed..860616be 100644 --- a/client/modules/edit.js +++ b/client/modules/edit.js @@ -1,4 +1,4 @@ -/* global CloudCmd, CloudFunc */ +/* global CloudCmd */ 'use strict'; @@ -6,6 +6,8 @@ const exec = require('execon'); const currify = require('currify/legacy'); const load = require('../dom/load'); + +const {MAX_FILE_SIZE: maxSize} = require('../../common/cloudfunc'); const {time, timeEnd} = require('../../common/util'); CloudCmd.Edit = EditProto; @@ -97,8 +99,6 @@ function EditProto(callback) { function _loadFiles(element, callback) { const socketPath = CloudCmd.PREFIX; - const maxSize = CloudFunc.MAX_FILE_SIZE; - const prefix = socketPath + '/' + EditorName; const url = prefix + '/' + EditorName + '.js'; diff --git a/client/modules/menu.js b/client/modules/menu.js index 01b4928b..87580848 100644 --- a/client/modules/menu.js +++ b/client/modules/menu.js @@ -1,4 +1,4 @@ -/* global CloudCmd, DOM, CloudFunc */ +/* global CloudCmd, DOM */ 'use strict'; @@ -7,8 +7,11 @@ CloudCmd.Menu = MenuProto; const exec = require('execon'); const currify = require('currify/legacy'); +const {FS} = require('../../common/cloudfunc'); + const load = require('../dom/load'); const RESTful = require('../dom/rest'); + const bind = (f, ...a) => (...b) => f(...a, ...b); function MenuProto(position) { @@ -261,7 +264,6 @@ function MenuProto(position) { function download(type) { const TIME = 30 * 1000; const prefixUr = CloudCmd.PREFIX_URL; - const FS = CloudFunc.FS; const PACK = '/pack'; const date = Date.now(); const files = DOM.getActiveFiles(); diff --git a/client/modules/view.js b/client/modules/view.js index ec8cbf64..2fd315f7 100644 --- a/client/modules/view.js +++ b/client/modules/view.js @@ -1,12 +1,14 @@ 'use strict'; -/* global CloudCmd, DOM, CloudFunc, $ */ +/* global CloudCmd, DOM, $ */ const itype = require('itype/legacy'); const rendy = require('rendy'); const exec = require('execon'); const {time} = require('../../common/util'); +const {FS} = require('../../common/cloudfunc'); + const Files = require('../dom/files'); const Events = require('../dom/events'); const load = require('../dom/load'); @@ -95,7 +97,7 @@ function ViewProto(callback) { } function show(data, options) { - const prefixUrl = CloudCmd.PREFIX_URL + CloudFunc.FS; + const prefixUrl = CloudCmd.PREFIX_URL + FS; if (Loading) return;