UNPKG

zcloudcmd

Version:

### [Main][MainURL] [Blog][BlogURL] Live([Heroku][HerokuURL], [Now][NowURL])

217 lines (201 loc) 25.2 kB
/******/ (function(modules) { // webpackBootstrap /******/ // install a JSONP callback for chunk loading /******/ function webpackJsonpCallback(data) { /******/ var chunkIds = data[0]; /******/ var moreModules = data[1]; /******/ var executeModules = data[2]; /******/ /******/ // add "moreModules" to the modules object, /******/ // then flag all "chunkIds" as loaded and fire callback /******/ var moduleId, chunkId, i = 0, resolves = []; /******/ for(;i < chunkIds.length; i++) { /******/ chunkId = chunkIds[i]; /******/ if(installedChunks[chunkId]) { /******/ resolves.push(installedChunks[chunkId][0]); /******/ } /******/ installedChunks[chunkId] = 0; /******/ } /******/ for(moduleId in moreModules) { /******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) { /******/ modules[moduleId] = moreModules[moduleId]; /******/ } /******/ } /******/ if(parentJsonpFunction) parentJsonpFunction(data); /******/ /******/ while(resolves.length) { /******/ resolves.shift()(); /******/ } /******/ /******/ // add entry modules from loaded chunk to deferred list /******/ deferredModules.push.apply(deferredModules, executeModules || []); /******/ /******/ // run deferred modules when all chunks ready /******/ return checkDeferredModules(); /******/ }; /******/ function checkDeferredModules() { /******/ var result; /******/ for(var i = 0; i < deferredModules.length; i++) { /******/ var deferredModule = deferredModules[i]; /******/ var fulfilled = true; /******/ for(var j = 1; j < deferredModule.length; j++) { /******/ var depId = deferredModule[j]; /******/ if(installedChunks[depId] !== 0) fulfilled = false; /******/ } /******/ if(fulfilled) { /******/ deferredModules.splice(i--, 1); /******/ result = __webpack_require__(__webpack_require__.s = deferredModule[0]); /******/ } /******/ } /******/ return result; /******/ } /******/ /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // object to store loaded and loading chunks /******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched /******/ // Promise = chunk loading, 0 = chunk loaded /******/ var installedChunks = { /******/ "./modules/operation": 0 /******/ }; /******/ /******/ var deferredModules = []; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = "/dist/"; /******/ /******/ var jsonpArray = window["webpackJsonp"] = window["webpackJsonp"] || []; /******/ var oldJsonpFunction = jsonpArray.push.bind(jsonpArray); /******/ jsonpArray.push = webpackJsonpCallback; /******/ jsonpArray = jsonpArray.slice(); /******/ for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]); /******/ var parentJsonpFunction = oldJsonpFunction; /******/ /******/ /******/ // add entry module to deferred list /******/ deferredModules.push(["./client/modules/operation/index.js","cloudcmd.common"]); /******/ // run deferred modules when ready /******/ return checkDeferredModules(); /******/ }) /************************************************************************/ /******/ ({ /***/ "./client/modules/operation/format.js": /*!********************************************!*\ !*** ./client/modules/operation/format.js ***! \********************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; eval("\n\nmodule.exports = (operation, from, to) => {\n if (!to)\n return `${operation} ${from}`;\n \n return `${operation} ${from} -> ${to}`;\n};\n\n\n\n//# sourceURL=file://cloudcmd/client/modules/operation/format.js"); /***/ }), /***/ "./client/modules/operation/get-next-current-name.js": /*!***********************************************************!*\ !*** ./client/modules/operation/get-next-current-name.js ***! \***********************************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; eval("\n\nconst currify = __webpack_require__(/*! currify/legacy */ \"./node_modules/currify/legacy/index.js\");\n\nconst not = currify((array, value) => !~array.indexOf(value));\nconst notOneOf = currify((a, b) => a.filter(not(b)));\n\nmodule.exports = (currentName, names, removedNames) => {\n const i = names.indexOf(currentName);\n \n const nextNames = notOneOf(names, removedNames);\n const {length} = nextNames;\n \n if (nextNames[i])\n return nextNames[i];\n \n return nextNames[length - 1];\n};\n\n\n\n//# sourceURL=file://cloudcmd/client/modules/operation/get-next-current-name.js"); /***/ }), /***/ "./client/modules/operation/index.js": /*!*******************************************!*\ !*** ./client/modules/operation/index.js ***! \*******************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; eval("/* global CloudCmd */\n/* global Util */\n/* global DOM */\n/* global fileop */\n\n\n\nconst currify = __webpack_require__(/*! currify/legacy */ \"./node_modules/currify/legacy/index.js\");\nconst wraptile = __webpack_require__(/*! wraptile/legacy */ \"./node_modules/wraptile/legacy/index.js\");\nconst {promisify} = __webpack_require__(/*! es6-promisify */ \"./node_modules/es6-promisify/dist/promisify.js\");\nconst exec = __webpack_require__(/*! execon */ \"./node_modules/execon/lib/exec.js\");\nconst loadJS = __webpack_require__(/*! load.js */ \"./node_modules/load.js/legacy/load.js\").js;\n\nconst {encode} = __webpack_require__(/*! ../../../common/entity */ \"./common/entity.js\");\n\nconst RESTful = __webpack_require__(/*! ../../dom/rest */ \"./client/dom/rest.js\");\nconst removeExtension = __webpack_require__(/*! ./remove-extension */ \"./client/modules/operation/remove-extension.js\");\nconst setListeners = __webpack_require__(/*! ./set-listeners */ \"./client/modules/operation/set-listeners.js\");\nconst getNextCurrentName = __webpack_require__(/*! ./get-next-current-name */ \"./client/modules/operation/get-next-current-name.js\");\n\nconst removeQuery = (a) => a.replace(/\\?.*/, '');\n\nconst Name = 'Operation';\nCloudCmd[Name] = exports;\n\nconst {\n TITLE,\n config,\n} = CloudCmd;\nconst {Dialog, Images} = DOM;\nconst initOperations = wraptile(_initOperations);\nconst authCheck = wraptile(_authCheck);\n\nconst Operation = {};\n\nlet Loaded;\n\nlet {\n cp: copyFn,\n mv: moveFn,\n delete: deleteFn,\n extract: extractFn,\n} = RESTful;\n\nlet packZipFn = RESTful.pack;\nlet packTarFn = RESTful.pack;\n\nconst Info = DOM.CurrentInfo;\nconst showLoad = Images.show.load.bind(null, 'top');\n\nconst processFiles = currify(_processFiles);\n\nconst noFilesCheck = () => {\n const {length} = DOM.getActiveFiles();\n const is = Boolean(!length);\n \n if (is)\n return Dialog.alert.noFiles(TITLE);\n \n return is;\n};\n\nmodule.exports.init = promisify((callback) => {\n showLoad();\n \n exec.series([\n DOM.loadSocket,\n (callback) => {\n if (!config('progress') || config('dropbox'))\n return callback();\n \n const {\n prefix,\n prefixSocket,\n } = CloudCmd;\n load(initOperations(prefix, prefixSocket, callback));\n },\n (callback) => {\n Loaded = true;\n Images.hide();\n callback();\n },\n ], callback);\n});\n\nfunction _authCheck(spawn, ok) {\n const accept = wraptile(ok);\n const alertDialog = wraptile(Dialog.alert);\n \n spawn.on('accept', accept(spawn));\n spawn.on('reject', alertDialog (TITLE, 'Wrong credentials!'));\n spawn.emit('auth', config('username'), config('password'));\n}\n\nfunction _initOperations(prefix, socketPrefix, fn) {\n socketPrefix = `${socketPrefix}/fileop`;\n fileop({prefix, socketPrefix}, (e, operator) => {\n fn();\n \n operator.on('connect', authCheck(operator, onConnect));\n operator.on('disconnect', onDisconnect);\n });\n}\n\nfunction onConnect(operator) {\n packTarFn = ({from, to, names}, callback) => {\n const operation = 'Tar';\n const listen = setListeners({\n operation,\n callback,\n noContinue: true,\n from,\n to,\n });\n \n operator.tar(from, to, names)\n .then(listen);\n };\n \n packZipFn = ({from, to, names}, callback) => {\n const operation = 'Zip';\n const listen = setListeners({\n operation,\n callback,\n noContinue: true,\n from,\n to,\n });\n \n operator.zip(from, to, names)\n .then(listen);\n };\n \n deleteFn = (from, files, callback) => {\n from = removeQuery(from);\n \n const operation = 'Delete';\n const listen = setListeners({\n operation,\n callback,\n from,\n });\n \n operator.remove(from, files)\n .then(listen);\n };\n \n copyFn = ({from, to, names}, callback) => {\n const operation = 'Copy';\n const listen = setListeners({\n operation,\n callback,\n from,\n to,\n names,\n });\n \n operator.copy(from, to, names)\n .then(listen);\n };\n \n moveFn = ({from, to, names}, callback) => {\n const operation = 'Move';\n const listen = setListeners({\n operation,\n callback,\n from,\n to,\n });\n \n operator.move(from, to, names)\n .then(listen);\n };\n \n extractFn = ({from, to}, callback) => {\n const operation = 'Extract';\n const listen = setListeners({\n operation,\n callback,\n noContinue: true,\n from,\n to,\n });\n \n operator.extract(from, to)\n .then(listen);\n };\n}\n\nfunction onDisconnect() {\n packZipFn = RESTful.pack;\n packTarFn = RESTful.pack;\n deleteFn = RESTful.delete;\n copyFn = RESTful.cp;\n moveFn = RESTful.mv;\n extractFn = RESTful.extract;\n}\n\nfunction getPacker(type) {\n if (type === 'zip')\n return packZipFn;\n \n return packTarFn;\n}\n\nmodule.exports.hide = () => {\n CloudCmd.View.hide();\n};\n\nmodule.exports.show = (operation, data) => {\n if (!Loaded)\n return;\n \n if (operation === 'copy')\n return Operation.copy(data);\n \n if (operation === 'move')\n return Operation.move(data);\n \n if (operation === 'delete')\n return Operation.delete();\n \n if (operation === 'delete:silent')\n return Operation.deleteSilent();\n \n if (operation === 'pack')\n return Operation.pack();\n \n if (operation === 'extract')\n return Operation.extract();\n};\n\nOperation.copy = processFiles({\n type: 'copy',\n});\n\nOperation.move = processFiles({\n type: 'move',\n});\n\nOperation.delete = () => {\n promptDelete();\n};\n\nOperation.deleteSilent = () => {\n deleteSilent();\n};\n\nOperation.pack = () => {\n const isZip = config('packer') === 'zip';\n twopack('pack', isZip ? 'zip' : 'tar');\n};\n\nOperation.extract = () => {\n twopack('extract');\n};\n\n/**\n * prompt and delete current file or selected files\n *\n * @currentFile\n */\nfunction promptDelete() {\n if (noFilesCheck())\n return;\n \n const msgAsk = 'Do you really want to delete the ';\n const msgSel = 'selected ';\n \n const files = DOM.getActiveFiles();\n const names = DOM.getFilenames(files);\n const n = names.length;\n \n let msg;\n \n if (n) {\n let name = '';\n \n for (let i = 0; i < 5 && i < n; i++)\n name += '\\n' + names[i];\n \n if (n >= 5)\n name += '\\n...';\n \n msg = msgAsk + msgSel + n + ' files/directories?\\n' + encode(name);\n } else {\n const current = DOM.getCurrentFile();\n const isDir = DOM.isCurrentIsDir(current);\n const getType = (isDir) => {\n return isDir ? 'directory' : 'file';\n };\n \n const type = getType(isDir) + ' ';\n \n const name = DOM.getCurrentName(current);\n msg = msgAsk + msgSel + type + name + '?';\n }\n \n const cancel = false;\n \n Dialog.confirm(TITLE, msg, {cancel}).then(() => {\n deleteSilent(files);\n });\n}\n\n/**\n * delete current or selected files\n *\n * @files\n */\nfunction deleteSilent(files = DOM.getActiveFiles()) {\n const query = '?files';\n const path = Info.dirPath;\n \n if (noFilesCheck())\n return;\n \n showLoad();\n \n const removedNames = DOM.getFilenames(files);\n const names = DOM.CurrentInfo.files.map(DOM.getCurrentName);\n const currentName = DOM.getCurrentName();\n const nextCurrentName = getNextCurrentName(currentName, names, removedNames);\n \n deleteFn(path + query, removedNames, () => {\n CloudCmd.refresh(() => {\n const names = Info.files.map(DOM.getCurrentName);\n const isCurrent = names.includes(currentName);\n \n const name = isCurrent ? currentName : nextCurrentName;\n \n DOM.setCurrentByName(name);\n });\n });\n}\n\n/*\n * process files (copy or move)\n * @param data\n * @param operation\n */\nfunction _processFiles(options, data) {\n let selFiles;\n let files;\n let panel;\n let shouldAsk;\n let ok;\n \n let from = '';\n let to = '';\n \n let names = [];\n \n /* eslint no-multi-spaces: 0 */\n \n if (data) {\n from = data.from;\n to = data.to;\n names = data.names;\n panel = Info.panel;\n } else {\n from = Info.dirPath;\n to = DOM.getNotCurrentDirPath();\n selFiles = DOM.getSelectedFiles();\n names = DOM.getFilenames(selFiles);\n data = {};\n shouldAsk = true;\n panel = Info.panelPassive;\n }\n \n if (!names.length)\n names.push(DOM.getCurrentName());\n \n const [name] = names;\n \n const sameName = DOM.getCurrentByName(name, panel);\n \n if (!data && noFilesCheck())\n return;\n \n const {type} = options;\n \n const isCopy = type === 'copy';\n const option = isCopy ? 'confirmCopy' : 'confirmMove';\n const title = isCopy ? 'Copy' : 'Rename/Move';\n const operation = isCopy ? copyFn : moveFn;\n \n if (shouldAsk && config(option))\n return message(title, to, names.map(encode))\n .then(ask);\n \n ask(to);\n \n function ask(to) {\n ok = from !== to && to;\n \n if (ok && !shouldAsk || !sameName)\n return go();\n \n const str = `\"${ name }\" already exist. Overwrite?`;\n const cancel = false;\n \n Dialog.confirm(TITLE, str, {cancel}).then(go);\n \n function go() {\n showLoad();\n \n files = {\n from,\n to,\n names,\n };\n \n operation(files, () => {\n DOM.Storage.remove(from, () => {\n const {\n panel,\n panelPassive,\n } = Info;\n \n const setCurrent = () => {\n const currentName = name || data.names[0];\n DOM.setCurrentByName(currentName);\n };\n \n if (!Info.isOnePanel)\n CloudCmd.refresh({\n panel: panelPassive,\n noCurrent: true,\n });\n \n CloudCmd.refresh({panel}, setCurrent);\n });\n });\n }\n }\n}\n\nfunction checkEmpty(name, operation) {\n if (!operation)\n throw Error(name + ' could not be empty!');\n}\n\nfunction twopack(operation, type) {\n let op;\n let fileFrom;\n let currentName = Info.name;\n \n const {\n path,\n dirPath,\n } = Info;\n \n const activeFiles = DOM.getActiveFiles();\n const names = DOM.getFilenames(activeFiles);\n \n checkEmpty('operation', operation);\n \n if (!names.length)\n return Dialog.alert.noFiles(TITLE);\n \n switch(operation) {\n case 'extract':\n op = extractFn;\n \n fileFrom = {\n from: path,\n to: dirPath,\n };\n \n currentName = removeExtension(currentName);\n \n break;\n \n case 'pack':\n op = getPacker(type);\n \n if (names.length > 1)\n currentName = Info.dir;\n \n currentName += DOM.getPackerExt(type);\n \n fileFrom = {\n from: dirPath,\n to: dirPath + currentName,\n names,\n };\n break;\n }\n \n showLoad();\n \n op(fileFrom, (error) => {\n !error && CloudCmd.refresh({\n currentName,\n });\n });\n}\n\nfunction message(msg, to, names) {\n const n = names.length;\n const [name] = names;\n \n msg += ' ';\n \n if (names.length > 1)\n msg += n + ' file(s)';\n else\n msg += '\"' + name + '\"';\n \n msg += ' to';\n \n const cancel = false;\n \n return Dialog.prompt(TITLE, msg, to, {cancel});\n}\n\nfunction load(callback) {\n const {prefix} = CloudCmd;\n const file = `${prefix}/fileop/fileop.js`;\n \n loadJS(file, (error) => {\n if (error) {\n Dialog.alert(TITLE, error.message);\n return exec(callback);\n }\n \n Loaded = true;\n Util.timeEnd(Name + ' load');\n exec(callback);\n });\n \n Util.time(Name + ' load');\n}\n\n\n\n//# sourceURL=file://cloudcmd/client/modules/operation/index.js"); /***/ }), /***/ "./client/modules/operation/remove-extension.js": /*!******************************************************!*\ !*** ./client/modules/operation/remove-extension.js ***! \******************************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; eval("\n\nconst {getExt} = __webpack_require__(/*! ../../../common/util */ \"./common/util.js\");\n\nmodule.exports = (name) => {\n const ext = getExtension(name);\n \n return name.replace(ext, '');\n};\n\nfunction getExtension(name) {\n if (/\\.tar\\.gz$/.test(name))\n return '.tar.gz';\n \n if (/\\.tar\\.bz2$/.test(name))\n return '.tar.bz2';\n \n return getExt(name);\n}\n\n\n\n//# sourceURL=file://cloudcmd/client/modules/operation/remove-extension.js"); /***/ }), /***/ "./client/modules/operation/set-listeners.js": /*!***************************************************!*\ !*** ./client/modules/operation/set-listeners.js ***! \***************************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; eval("\n\n/* global DOM */\n/* global CloudCmd */\n\nconst smalltalk = __webpack_require__(/*! smalltalk */ \"./node_modules/smalltalk/legacy/smalltalk.js\");\n\nconst {\n Dialog,\n Images,\n} = DOM;\n\nconst forEachKey = __webpack_require__(/*! for-each-key/legacy */ \"./node_modules/for-each-key/legacy/index.js\");\nconst wraptile = __webpack_require__(/*! wraptile/legacy */ \"./node_modules/wraptile/legacy/index.js\");\nconst {TITLE} = CloudCmd;\n\nconst format = __webpack_require__(/*! ./format */ \"./client/modules/operation/format.js\");\n\nmodule.exports = (options) => (emitter) => {\n const {\n operation,\n callback,\n noContinue,\n from,\n to,\n } = options;\n \n let done;\n let lastError;\n \n const onAbort = wraptile(({emitter, operation}) => {\n emitter.abort();\n \n const msg = `${operation} aborted`;\n lastError = true;\n \n Dialog.alert(TITLE, msg, {\n noCancel: true,\n });\n });\n \n const removeListener = emitter.removeListener.bind(emitter);\n const on = emitter.on.bind(emitter);\n \n const message = format(operation, from, to);\n \n const progress = smalltalk.progress(TITLE, message);\n \n progress.catch(onAbort({\n emitter,\n operation,\n }));\n \n const listeners = {\n progress: (value) => {\n done = value === 100;\n progress.setProgress(value);\n },\n \n end: () => {\n Images.hide();\n forEachKey(removeListener, listeners);\n \n if (lastError || done)\n callback();\n },\n \n error: (error) => {\n lastError = error;\n \n if (noContinue) {\n listeners.end(error);\n Dialog.alert(TITLE, error);\n return;\n }\n \n Dialog.confirm(TITLE, error + '\\n Continue?')\n .then(() => {\n emitter.continue();\n }, () => {\n emitter.abort();\n });\n },\n };\n \n forEachKey(on, listeners);\n};\n\n\n\n//# sourceURL=file://cloudcmd/client/modules/operation/set-listeners.js"); /***/ }) /******/ });