diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js index 566062d5..9c4b5a34 100755 --- a/bin/cloudcmd.js +++ b/bin/cloudcmd.js @@ -305,7 +305,9 @@ function checkUpdate() { } function showUpdateInfo(data) { - const version = data.version; + const { + version + } = data; if (version === Info.version) return; diff --git a/bin/release.js b/bin/release.js index c5a65cd2..73886eb5 100755 --- a/bin/release.js +++ b/bin/release.js @@ -24,7 +24,9 @@ function main(callback) { '**[v{{ version }}]' + '(' + link + 'v{{ version }})**\n'; - const version = Info.version; + const { + version + } = Info; cl((error, versionNew) => { if (error) @@ -52,7 +54,9 @@ function replaceVersion(name, version, versionNew, callback) { } function cl(callback) { - const argv = process.argv; + const { + argv + } = process; const length = argv.length - 1; const last = process.argv[length]; const regExp = /^--(major|minor|patch)$/; diff --git a/client/client.js b/client/client.js index 60ec4392..a6c42526 100644 --- a/client/client.js +++ b/client/client.js @@ -55,8 +55,11 @@ function CloudCmdProto(DOM) { const CloudCmd = this; const Info = DOM.CurrentInfo; - const Storage = DOM.Storage; - const Files = DOM.Files; + + const { + Storage, + Files + } = DOM; this.log = log; this.prefix = ''; @@ -97,10 +100,13 @@ function CloudCmdProto(DOM) { const p = params; const refresh = p.isRefresh; - const panel = p.panel; - const history = p.history; - const noCurrent = p.noCurrent; - const currentName = p.currentName; + + const { + panel, + history, + noCurrent, + currentName + } = p; let panelChanged; if (!noCurrent) @@ -154,7 +160,7 @@ function CloudCmdProto(DOM) { * should be called from config.js only * after successful update on server */ - + if (key === 'password') return; @@ -317,14 +323,16 @@ function CloudCmdProto(DOM) { callback = options; options = {}; } - + const panel = options.panel || Info.panel; const path = DOM.getCurrentDirPath(panel); const isRefresh = true; const history = false; const noCurrent = options ? options.noCurrent : false; - const currentName = options.currentName; + const { + currentName + } = options; CloudCmd.loadDir({ path, @@ -348,11 +356,15 @@ function CloudCmdProto(DOM) { */ function ajaxLoad(path, options, panel, callback) { const create = (error, json) => { - const RESTful = DOM.RESTful; + const { + RESTful + } = DOM; const name = options.currentName || Info.name; const obj = jonny.parse(json); const isRefresh = options.refresh; - const noCurrent = options.noCurrent; + const { + noCurrent + } = options; if (!isRefresh && json) return createFileTable(obj, panel, options, callback); @@ -414,7 +426,9 @@ function CloudCmdProto(DOM) { const names = ['file', 'path', 'link', 'pathLink']; Files.get(names, (error, templFile, templPath, templLink, templPathLink) => { - const Dialog = DOM.Dialog; + const { + Dialog + } = DOM; const panel = panelParam || DOM.getPanel(); const {prefix} = CloudCmd; @@ -426,7 +440,9 @@ function CloudCmdProto(DOM) { if (error) return Dialog.alert(TITLE, error.responseText); - const childNodes = panel.childNodes; + const { + childNodes + } = panel; let i = childNodes.length; while (i--) @@ -510,10 +526,10 @@ function CloudCmdProto(DOM) { } this.goToParentDir = () => { - const dir = Info.dir; const { + dir, dirPath, - parentDirPath, + parentDirPath } = Info; if (dirPath === parentDirPath) diff --git a/client/dom/buffer.js b/client/dom/buffer.js index 39ce58ae..a5f1fd2a 100644 --- a/client/dom/buffer.js +++ b/client/dom/buffer.js @@ -108,16 +108,18 @@ function BufferProto() { exec.parallel([copy, cut], (error, cp, ct) => { const opStr = cp ? 'copy' : 'move'; const opData = cp || ct; - const Operation = CloudCmd.Operation; + const { + Operation + } = CloudCmd; const msg = 'Path is same!'; const path = Info.dirPath; if (!error && !cp && !ct) error = 'Buffer is empty!'; - + if (error) return showMessage(error); - + const data = jonny.parse(opData); data.to = path; diff --git a/client/dom/directory.js b/client/dom/directory.js index 5740b91b..9d5c58a1 100644 --- a/client/dom/directory.js +++ b/client/dom/directory.js @@ -13,7 +13,9 @@ const { } = DOM; module.exports = (items) => { - const Dialog = DOM.Dialog; + const { + Dialog + } = DOM; if (items.length) Images.show('top'); diff --git a/client/dom/dom-tree.js b/client/dom/dom-tree.js index c96dc88d..22103cff 100644 --- a/client/dom/dom-tree.js +++ b/client/dom/dom-tree.js @@ -20,7 +20,9 @@ const isContainClass = (element, className) => { if (Array.isArray(className)) return className.some(currify(isContainClass, element)); - const classList = element.classList; + const { + classList + } = element; return classList.contains(className); }; diff --git a/client/dom/images.js b/client/dom/images.js index 9e9c3fe8..275bf910 100644 --- a/client/dom/images.js +++ b/client/dom/images.js @@ -47,7 +47,9 @@ function getElement() { /* Функция создаёт картинку загрузки */ module.exports.loading = () => { const element = getElement(); - const classList = element.classList; + const { + classList + } = element; classList.add(LOADING, LoadingImage); classList.remove(ERROR, HIDDEN); @@ -58,7 +60,9 @@ module.exports.loading = () => { /* Функция создаёт картинку ошибки загрузки */ module.exports.error = () => { const element = getElement(); - const classList = element.classList; + const { + classList + } = element; classList.add(ERROR); classList.remove(HIDDEN, LOADING, LoadingImage); @@ -80,7 +84,7 @@ function show(position, panel) { const refreshButton = DOM.getRefreshButton(panel); let current; - + if (position === 'top') { current = refreshButton.parentElement; } else { @@ -123,7 +127,7 @@ module.exports.hide = () => { module.exports.setProgress = (value, title) => { const DATA = 'data-progress'; const element = Images.get(); - + if (!element) return Images; diff --git a/client/dom/index.js b/client/dom/index.js index 7f63cf66..e2b888b6 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -90,7 +90,7 @@ function CmdProto() { if (name === '..') return ''; - + return name; }; @@ -247,7 +247,7 @@ function CmdProto() { RESTful.read(link + query, (error, size) => { if (error) return; - + DOM.setCurrentSize(size, current); exec(callback, current); Images.hide(); @@ -319,7 +319,9 @@ function CmdProto() { */ this.getCurrentData = (callback, currentFile) => { let hash; - const Dialog = DOM.Dialog; + const { + Dialog + } = DOM; const Info = DOM.CurrentInfo; const current = currentFile || DOM.getCurrentFile(); const path = DOM.getCurrentPath(current); @@ -332,7 +334,9 @@ function CmdProto() { if (itype.object(data)) data = jonny.stringify(data); - const length = data.length; + const { + length + } = data; if (hash && length < ONE_MEGABYTE) DOM.saveDataToStorage(path, data, hash); @@ -448,7 +452,9 @@ function CmdProto() { */ this.expandSelection = () => { const msg = 'expand'; - const files = CurrentInfo.files; + const { + files + } = CurrentInfo; selectByPattern(msg, files); }; @@ -458,8 +464,10 @@ function CmdProto() { */ this.shrinkSelection = () => { const msg = 'shrink'; - const files = CurrentInfo.files; - + const { + files + } = CurrentInfo; + selectByPattern(msg, files); }; @@ -540,7 +548,9 @@ function CmdProto() { * check storage hash */ this.checkStorageHash = (name, callback) => { - const parallel = exec.parallel; + const { + parallel + } = exec; const loadHash = DOM.loadCurrentHash; const nameHash = name + '-hash'; const getStoreHash = exec.with(Storage.get, nameHash); @@ -694,7 +704,7 @@ function CmdProto() { return DOM.hide(panel); }; - + /** * remove child of element * @param pChild @@ -748,7 +758,9 @@ function CmdProto() { * @currentFile */ this.renameCurrent = (current) => { - const Dialog = DOM.Dialog; + const { + Dialog + } = DOM; if (!DOM.isCurrentFile(current)) current = DOM.getCurrentFile(); @@ -824,7 +836,7 @@ function CmdProto() { let dataName = panel.getAttribute('data-name'); TabPanel[dataName] = name; - + panel = panelPassive; dataName = panel.getAttribute('data-name'); @@ -866,7 +878,9 @@ function CmdProto() { this.goToDirectory = () => { const msg = 'Go to directory:'; const path = CurrentInfo.dirPath; - const Dialog = DOM.Dialog; + const { + Dialog + } = DOM; const cancel = false; const setPath = (path) => ({ path @@ -879,7 +893,9 @@ function CmdProto() { this.duplicatePanel = () => { const Info = CurrentInfo; - const isDir = Info.isDir; + const { + isDir + } = Info; const panel = Info.panelPassive; const noCurrent = !Info.isOnePanel; @@ -901,11 +917,12 @@ function CmdProto() { this.swapPanels = () => { const Info = CurrentInfo; - const {panel} = Info; - const {files} = Info; - const {element} = Info; - - const panelPassive = Info.panelPassive; + const { + panel, + files, + element, + panelPassive + } = Info; const dirPath = DOM.getCurrentDirPath(); const dirPathPassive = DOM.getNotCurrentDirPath(); @@ -922,7 +939,9 @@ function CmdProto() { path: dirPathPassive, panel }, () => { - const files = Info.files; + const { + files + } = Info; const length = files.length - 1; if (currentIndex > length) diff --git a/client/dom/load-remote.js b/client/dom/load-remote.js index bc3dc625..05090c42 100644 --- a/client/dom/load-remote.js +++ b/client/dom/load-remote.js @@ -25,7 +25,9 @@ module.exports = (name, options, callback = options) => { const module = findObjByNameInArr(modules.remote, name); const isArray = itype.array(module.local); - const version = module.version; + const { + version + } = module; let remoteTmpls; let local; diff --git a/client/dom/rest.js b/client/dom/rest.js index 622688ca..12b7cfb6 100644 --- a/client/dom/rest.js +++ b/client/dom/rest.js @@ -194,8 +194,12 @@ function RESTful() { dataType : p.dataType, error : (jqXHR) => { const response = jqXHR.responseText; - const statusText = jqXHR.statusText; - const status = jqXHR.status; + + const { + statusText, + status + } = jqXHR; + const text = status === 404 ? response : statusText; const encoded = encode(text); diff --git a/client/dom/upload-files.js b/client/dom/upload-files.js index 288ab24b..66754014 100644 --- a/client/dom/upload-files.js +++ b/client/dom/upload-files.js @@ -47,7 +47,9 @@ function _onEnd(currentName) { function _loadFile(dir, n, file, callback) { let i = 0; - const name = file.name; + const { + name + } = file; const path = dir + name; const {prefixURL} = CloudCmd; const api = prefixURL + FS; diff --git a/client/input.js b/client/input.js index 459ca7a4..c9d59b6d 100644 --- a/client/input.js +++ b/client/input.js @@ -52,7 +52,9 @@ function setState(state) { module.exports.getValue = (name, element) => { const el = getElementByName(name, element); - const type = el.type; + const { + type + } = el; switch(type) { case 'checkbox': @@ -68,7 +70,9 @@ module.exports.getValue = (name, element) => { module.exports.setValue = (name, value, element) => { const el = getElementByName(name, element); - const type = el.type; + const { + type + } = el; switch(type) { case 'checkbox': diff --git a/client/key/index.js b/client/key/index.js index 3e145f29..53a86452 100644 --- a/client/key/index.js +++ b/client/key/index.js @@ -56,7 +56,9 @@ function KeyProto() { } function listener(event) { - const keyCode = event.keyCode; + const { + keyCode + } = event; const alt = event.altKey; const ctrl = event.ctrlKey; const shift = event.shiftKey; @@ -121,14 +123,19 @@ function KeyProto() { let current = Info.element; let dataName; - const name = Info.name; + const { + name, + panel, + path, + isDir + } = Info; const {Operation} = CloudCmd; - const panel = Info.panel; - const path = Info.path; - const isDir = Info.isDir; - const keyCode = event.keyCode; + const { + keyCode + } = event; + const alt = event.altKey; const shift = event.shiftKey; const ctrl = event.ctrlKey; @@ -185,7 +192,7 @@ function KeyProto() { case Key.F2: DOM.renameCurrent(current); break; - + case Key.F3: if (shift) CloudCmd.Markdown.show(path); @@ -326,7 +333,7 @@ function KeyProto() { case Key.RIGHT: if (!alt) return; - + event.preventDefault(); dataName = Info.panel.getAttribute('data-name'); @@ -378,7 +385,7 @@ function KeyProto() { DOM.setCurrentFile(current); event.preventDefault(); break; - + /* open directory */ case Key.ENTER: if (Info.isDir) @@ -386,7 +393,7 @@ function KeyProto() { path: path === '/' ? '/' : path + '/' }); break; - + case Key.BACKSPACE: CloudCmd.goToParentDir(); event.preventDefault(); @@ -461,7 +468,7 @@ function KeyProto() { if (ctrlMeta) Buffer.cut(); break; - + case Key.V: if (ctrlMeta) Buffer.paste(); diff --git a/client/key/vim/index.js b/client/key/vim/index.js index 1c14d764..d9eb5130 100644 --- a/client/key/vim/index.js +++ b/client/key/vim/index.js @@ -3,7 +3,9 @@ const KEY = require('../key'); const Info = DOM.CurrentInfo; -const Dialog = DOM.Dialog; +const { + Dialog +} = DOM; const fullstore = require('fullstore/legacy'); const store = fullstore(''); @@ -33,7 +35,9 @@ const rmFirst = (a) => { module.exports = (key, event) => { const current = Info.element; - const keyCode = event.keyCode; + const { + keyCode + } = event; const prevStore = store(); const value = store(prevStore.concat(key)); @@ -118,7 +122,7 @@ module.exports = (key, event) => { Dialog.prompt(TITLE, 'Find', '', {cancel: false}) .then(find); - + return end(); } diff --git a/client/key/vim/index.spec.js b/client/key/vim/index.spec.js index 099607d4..6e3ef2c6 100644 --- a/client/key/vim/index.spec.js +++ b/client/key/vim/index.spec.js @@ -21,8 +21,12 @@ const { global.DOM = getDOM(); global.CloudCmd = getCloudCmd(); -const DOM = global.DOM; -const Buffer = DOM.Buffer; +const { + DOM +} = global; +const { + Buffer +} = DOM; const KEY = require(pathKey); const vim = require(pathVim); diff --git a/client/listeners/index.js b/client/listeners/index.js index 8c855c96..8ce5c694 100644 --- a/client/listeners/index.js +++ b/client/listeners/index.js @@ -51,7 +51,9 @@ const execAll = currify((funcs, event) => { }); const Info = DOM.CurrentInfo; -const Events = DOM.Events; +const { + Events +} = DOM; const EventsFiles = { mousedown: exec.with(execIfNotUL, setCurrentFileByEvent), click: execAll([ @@ -115,9 +117,13 @@ module.exports.initKeysPanel = () => { return; Events.addClick(keysElement, ({target}) => { - const id = target.id; + const { + id + } = target; const operation = (name) => { - const Operation = CloudCmd.Operation; + const { + Operation + } = CloudCmd; const fn = Operation.show.bind(null, name); return fn; @@ -138,7 +144,7 @@ module.exports.initKeysPanel = () => { 'shift~' : CloudCmd.Terminal.show, 'contact' : CloudCmd.Contact.show, }; - + exec(clickFuncs[id]); }); }; @@ -304,7 +310,9 @@ function onTouch(event) { function onDragStart(event) { const {prefixURL} = CloudCmd; const element = getLIElement(event.target); - const isDir = Info.isDir; + const { + isDir + } = Info; let link = DOM.getCurrentLink(element); let name = DOM.getCurrentName(element); @@ -407,8 +415,11 @@ function dragndrop() { }; const onDrop = (event) => { - const files = event.dataTransfer.files; - const items = event.dataTransfer.items; + const { + files, + items + } = event.dataTransfer; + const {length: filesCount} = files; event.preventDefault(); @@ -434,8 +445,12 @@ function dragndrop() { * to upload file from download bar */ const onDragOver = (event) => { - const dataTransfer = event.dataTransfer; - const effectAllowed = dataTransfer.effectAllowed; + const { + dataTransfer + } = event; + const { + effectAllowed + } = dataTransfer; if (/move|linkMove/.test(effectAllowed)) dataTransfer.dropEffect = 'move'; @@ -456,7 +471,9 @@ function dragndrop() { function unload() { DOM.Events.add(['unload', 'beforeunload'], (event) => { - const Key = CloudCmd.Key; + const { + Key + } = CloudCmd; const isBind = Key && Key.isBind(); if (isBind) diff --git a/client/modules/config.js b/client/modules/config.js index de7b6cef..c5fc06e1 100644 --- a/client/modules/config.js +++ b/client/modules/config.js @@ -57,9 +57,10 @@ module.exports.init = async () => { Loading = false; }; -const config = CloudCmd.config; - -const {Key} = CloudCmd; +const { + config, + Key +} = CloudCmd; let Element; let Template; diff --git a/client/modules/contact.js b/client/modules/contact.js index 0bd87725..f33cdd8b 100644 --- a/client/modules/contact.js +++ b/client/modules/contact.js @@ -8,8 +8,12 @@ CloudCmd.Contact = exports; const olark = require('@cloudcmd/olark'); const Images = require('../dom/images'); -const Events = DOM.Events; -const Key = CloudCmd.Key; +const { + Events +} = DOM; +const { + Key +} = CloudCmd; module.exports.show = show; module.exports.hide = hide; diff --git a/client/modules/edit-file.js b/client/modules/edit-file.js index 7fe98965..99fe5500 100644 --- a/client/modules/edit-file.js +++ b/client/modules/edit-file.js @@ -10,13 +10,19 @@ const exec = require('execon'); const supermenu = require('supermenu'); const Info = DOM.CurrentInfo; -const Dialog = DOM.Dialog; -const config = CloudCmd.config; + +const { + Dialog, + Images +} = DOM; + +const { + config +} = CloudCmd; let Menu; const TITLE = 'Edit'; -const Images = DOM.Images; let MSG_CHANGED; const isLoading = fullstore(); @@ -68,7 +74,9 @@ module.exports.show = (options) => { .setOption('keyMap', 'default'); Info.getData((error, data) => { - const path = Info.path; + const { + path + } = Info; const name = getName(); if (error) diff --git a/client/modules/edit-names.js b/client/modules/edit-names.js index e6e069bc..b67d96af 100644 --- a/client/modules/edit-names.js +++ b/client/modules/edit-names.js @@ -11,7 +11,9 @@ const supermenu = require('supermenu'); const reject = Promise.reject.bind(Promise); const Info = DOM.CurrentInfo; -const Dialog = DOM.Dialog; +const { + Dialog +} = DOM; const TITLE = 'Edit Names'; const alert = currify(Dialog.alert, TITLE); @@ -56,7 +58,7 @@ module.exports.show = (options) => { .disableKey(); CloudCmd.Edit.show(config); - + return CloudCmd.Edit; }; @@ -64,7 +66,9 @@ function keyListener(event) { const ctrl = event.ctrlKey; const meta = event.metaKey; const ctrlMeta = ctrl || meta; - const Key = CloudCmd.Key; + const { + Key + } = CloudCmd; if (!ctrlMeta || event.keyCode !== Key.S) return; diff --git a/client/modules/menu.js b/client/modules/menu.js index 60c71d32..02a82bd6 100644 --- a/client/modules/menu.js +++ b/client/modules/menu.js @@ -11,13 +11,19 @@ const {FS} = require('../../common/cloudfunc'); const {getIdBySrc} = require('../dom/load'); const RESTful = require('../dom/rest'); -const config = CloudCmd.config; -const Buffer = DOM.Buffer; +const { + config, + Key +} = CloudCmd; + +const { + Buffer, + Events, + Dialog, + Images +} = DOM; + const Info = DOM.CurrentInfo; -const Key = CloudCmd.Key; -const Events = DOM.Events; -const Dialog = DOM.Dialog; -const Images = DOM.Images; const TITLE = 'Cloud Commander'; const alertNoFiles = wrap(Dialog.alert.noFiles)(TITLE); const uploadTo = wrap(_uploadTo); @@ -190,7 +196,9 @@ function isPath(x, y) { } function beforeShow(callback, params) { - const name = params.name; + const { + name + } = params; let el = DOM.getCurrentByPosition({ x: params.x, y: params.y @@ -223,9 +231,11 @@ function _uploadTo(nameModule) { if (error) return; - const name = Info.name; + const { + name + } = Info; const execFrom = CloudCmd.execFromModule; - + execFrom(nameModule, 'uploadFile', name, data); }); @@ -241,7 +251,7 @@ function uploadFromCloud() { RESTful.write(path, data, (error) => { if (error) return; - + CloudCmd.refresh({currentName}); }); }); @@ -260,7 +270,7 @@ function download(type) { if (!files.length) return alertNoFiles(); - + files.forEach((file) => { const selected = DOM.isSelected(file); const isDir = DOM.isCurrentIsDir(file); @@ -312,8 +322,11 @@ function getCurrentPosition() { } function listener(event) { - const F9 = Key.F9; - const ESC = Key.ESC; + const { + F9, + ESC + } = Key; + const key = event.keyCode; const isBind = Key.isBind(); diff --git a/client/modules/operation/get-next-current-name.js b/client/modules/operation/get-next-current-name.js index dc2bed5e..e0256b2e 100644 --- a/client/modules/operation/get-next-current-name.js +++ b/client/modules/operation/get-next-current-name.js @@ -9,7 +9,9 @@ module.exports = (currentName, names, removedNames) => { const i = names.indexOf(currentName); const nextNames = notOneOf(names, removedNames); - const length = nextNames.length; + const { + length + } = nextNames; if (nextNames[i]) return nextNames[i]; diff --git a/client/modules/operation/index.js b/client/modules/operation/index.js index 2d8b1767..12927bc5 100644 --- a/client/modules/operation/index.js +++ b/client/modules/operation/index.js @@ -273,7 +273,7 @@ function deleteSilent(files = DOM.getActiveFiles()) { const isCurrent = names.includes(currentName); let name = isCurrent ? currentName : nextCurrentName; - + DOM.setCurrentByName(name); }); }); @@ -348,7 +348,7 @@ function _processFiles(options, data) { function go() { showLoad(); - + files = { from, to, @@ -390,9 +390,15 @@ function twopack(operation, type) { let fileFrom; let currentName = Info.name; - const Images = DOM.Images; - const path = Info.path; - const dirPath = Info.dirPath; + const { + Images + } = DOM; + + const { + path, + dirPath + } = Info; + const activeFiles = DOM.getActiveFiles(); const names = DOM.getFilenames(activeFiles); diff --git a/client/modules/terminal.js b/client/modules/terminal.js index 624ca8f0..5dd4f332 100644 --- a/client/modules/terminal.js +++ b/client/modules/terminal.js @@ -17,15 +17,16 @@ const loadParallel = promisify(load.parallel); const TITLE = 'Terminal'; const {Dialog} = DOM; -const {Key} = CloudCmd; +const { + Key, + config +} = CloudCmd; CloudCmd.Terminal = exports; let Loaded; let Terminal; -const {config} = CloudCmd; - const loadAll = async () => { const { prefix, diff --git a/client/modules/view.js b/client/modules/view.js index 278ce589..0e2df591 100644 --- a/client/modules/view.js +++ b/client/modules/view.js @@ -40,7 +40,9 @@ const Name = 'View'; CloudCmd[Name] = module.exports; const Info = DOM.CurrentInfo; -const Key = CloudCmd.Key; +const { + Key +} = CloudCmd; const basename = (a) => a.split('/').pop(); let El; @@ -313,7 +315,7 @@ function onOverlayClick(event) { x: event.clientX, y: event.clientY }; - + setCurrentByPosition(position); } diff --git a/client/sort.js b/client/sort.js index adf769c4..cfbad8b7 100644 --- a/client/sort.js +++ b/client/sort.js @@ -4,8 +4,12 @@ const DOM = require('./dom'); const Info = DOM.CurrentInfo; -const sort = CloudCmd.sort; -const order = CloudCmd.order; + +const { + sort, + order +} = CloudCmd; + const position = DOM.getPanelPosition(); let sortPrevious = sort[position]; diff --git a/common/cloudfunc.js b/common/cloudfunc.js index ab759bd4..861521fa 100644 --- a/common/cloudfunc.js +++ b/common/cloudfunc.js @@ -3,7 +3,9 @@ const rendy = require('rendy/legacy'); const currify = require('currify/legacy'); const store = require('fullstore/legacy'); -const encode = require('./entity').encode; +const { + encode +} = require('./entity'); const btoa = require('./btoa'); const getHeaderField = currify(_getHeaderField); @@ -42,7 +44,9 @@ module.exports.getTitle = (options) => { options = options || {}; const path = options.path || Path(); - const name = options.name; + const { + name + } = options; const array = [ name || NAME, @@ -107,14 +111,20 @@ const getDataName = (name) => { * */ module.exports.buildFromJSON = (params) => { - const prefix = params.prefix; - const template = params.template; + const { + prefix, + template + } = params; + const templateFile = template.file; const templateLink = template.link; const json = params.data; const path = encode(json.path); - const files = json.files; + + const { + files + } = json; const sort = params.sort || 'name'; const order = params.order || 'asc'; @@ -188,12 +198,14 @@ module.exports.buildFromJSON = (params) => { const name = encode(file.name); const link = prefix + FS + path + name; - const {type} = file; + const { + type, + mode + } = file; const size = getSize(file); const date = file.date || '--.--.----'; const owner = file.owner || 'root'; - const mode = file.mode; const linkResult = rendy(templateLink, { link, diff --git a/server/config.js b/server/config.js index bf36c29b..4ff8c7cf 100644 --- a/server/config.js +++ b/server/config.js @@ -31,7 +31,9 @@ const save = promisify(_save); const formatMsg = currify((a, b) => CloudFunc.formatMsg(a, b)); -const apiURL = CloudFunc.apiURL; +const { + apiURL +} = CloudFunc; const changeEmitter = new Emitter(); const ConfigPath = path.join(DIR, 'json/config.json'); @@ -108,7 +110,7 @@ function listen(sock, auth) { .on('connection', (socket) => { if (!manage('auth')) return connection(socket); - + const reject = () => socket.emit('reject'); socket.on('auth', auth(connectionWraped(socket), reject)); }); @@ -145,7 +147,7 @@ function middle(req, res, next) { if (req.url !== `${apiURL}/config`) return next(); - + switch(req.method) { case 'GET': get(req, res, next); @@ -156,7 +158,7 @@ function middle(req, res, next) { return res .status(404) .send('Config is disabled'); - + patch(req, res); break; diff --git a/server/distribute/export.js b/server/distribute/export.js index bebe8905..55d7281d 100644 --- a/server/distribute/export.js +++ b/server/distribute/export.js @@ -8,15 +8,16 @@ const omit = require('object.omit'); const config = require('../config'); const log = require('./log'); -const exportStr = log.exportStr; -const connectedStr = log.connectedStr; -const disconnectedStr = log.disconnectedStr; -const authTryStr = log.authTryStr; - -const makeColor = log.makeColor; -const getMessage = log.getMessage; -const getDescription = log.getDescription; -const logWraped = log.logWraped; +const { + exportStr, + connectedStr, + disconnectedStr, + authTryStr, + makeColor, + getMessage, + getDescription, + logWraped +} = log; const omitList = [ 'auth', @@ -66,10 +67,15 @@ const push = currify((socket, key, value) => { }); function getHost(socket) { - const remoteAddress = socket.request.connection.remoteAddress; - const name = socket.handshake.query.name; - const port = socket.handshake.query.port; - const color = socket.handshake.query.color; + const { + remoteAddress + } = socket.request.connection; + + const { + name, + port, + color + } = socket.handshake.query; if (!name) return `${remoteAddress}:${port}`; diff --git a/server/distribute/import.js b/server/distribute/import.js index 7888d5c5..a4ffa9a9 100644 --- a/server/distribute/import.js +++ b/server/distribute/import.js @@ -11,17 +11,18 @@ const forEachKey = currify(require('for-each-key')); const config = require('../config'); const log = require('./log'); -const importStr = log.importStr; -const connectedStr = log.connectedStr; -const disconnectedStr = log.disconnectedStr; -const tokenRejectedStr = log.tokenRejectedStr; -const authTryStr = log.authTryStr; - -const makeColor = log.makeColor; -const stringToRGB = log.stringToRGB; -const getMessage = log.getMessage; -const getDescription = log.getDescription; -const logWraped = log.logWraped; +const { + importStr, + connectedStr, + disconnectedStr, + tokenRejectedStr, + authTryStr, + makeColor, + stringToRGB, + getMessage, + getDescription, + logWraped +} = log; const equal = (a, b) => `${a}=${b}`; const append = currify((obj, a, b) => obj.value += b && equal(a, b) + '&'); diff --git a/server/env.js b/server/env.js index 1baeccc8..a42664d4 100644 --- a/server/env.js +++ b/server/env.js @@ -1,6 +1,8 @@ 'use strict'; -const env = process.env; +const { + env +} = process; const up = (a) => a.toUpperCase(); module.exports = parse; diff --git a/server/repl.js b/server/repl.js index a24c7d0b..c602d89d 100644 --- a/server/repl.js +++ b/server/repl.js @@ -4,7 +4,9 @@ const net = require('net'); const repl = require('repl'); module.exports = net.createServer((socket) => { - const pid = process.pid; + const { + pid + } = process; const addr = socket.remoteAddress; const port = socket.remotePort; @@ -15,7 +17,7 @@ module.exports = net.createServer((socket) => { terminal: true, useGlobal: false }); - + r.on('exit', () => { socket.end(); }); diff --git a/server/rest/index.js b/server/rest/index.js index d79c59e5..523e840b 100644 --- a/server/rest/index.js +++ b/server/rest/index.js @@ -84,7 +84,9 @@ function sendData(params, callback) { if (isMD) return markdown(p.name, p.request, callback); - const method = p.request.method; + const { + method + } = p.request; switch(method) { case 'GET': @@ -179,7 +181,9 @@ function onPUT(name, body, callback) { const from = root(files.from); const to = root(files.to); - const names = files.names; + const { + names + } = files; if (!names) return fs.rename(from, to, fn); @@ -193,7 +197,7 @@ function onPUT(name, body, callback) { if (isRootAll([files.to, files.from])) return callback(getWin32RootMsg()); - + files.from = root(files.from); files.to = root(files.to); diff --git a/server/rest/info.js b/server/rest/info.js index 11da857c..787d70eb 100644 --- a/server/rest/info.js +++ b/server/rest/info.js @@ -2,11 +2,15 @@ const format = require('format-io'); -const version = require('../../package').version; +const { + version +} = require('../../package'); const config = require('../config'); const getMemory = () => { - const rss = process.memoryUsage().rss; + const { + rss + } = process.memoryUsage(); return format.size(rss); }; diff --git a/server/route.js b/server/route.js index 53b68536..b9d5b24d 100644 --- a/server/route.js +++ b/server/route.js @@ -113,9 +113,13 @@ function indexProcessing(options) { const noConfig = !config('configDialog'); const noConsole = !config('console'); const noTerminal = !config('terminal'); - const panel = options.panel; + const { + panel + } = options; - let data = options.data; + let { + data + } = options; if (noKeysPanel) data = hideKeysPanel(data);