cloudcmd 16.15.0 → 16.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CONTRIBUTING.md +6 -6
  2. package/ChangeLog +10 -0
  3. package/HELP.md +55 -50
  4. package/README.md +1 -1
  5. package/bin/cloudcmd.mjs +22 -25
  6. package/bin/release.mjs +6 -7
  7. package/common/base64.js +2 -3
  8. package/common/callbackify.js +0 -1
  9. package/common/cloudfunc.js +12 -13
  10. package/common/datetime.js +1 -1
  11. package/common/entity.js +1 -2
  12. package/common/try-to-promise-all.js +0 -1
  13. package/common/util.js +3 -3
  14. package/dist/cloudcmd.common.js.map +1 -1
  15. package/dist/cloudcmd.css +1 -1
  16. package/dist/cloudcmd.js.map +1 -1
  17. package/dist/modules/operation.js.map +1 -1
  18. package/dist/modules/view.js.map +1 -1
  19. package/dist/sw.js +1 -1
  20. package/dist/sw.js.map +1 -1
  21. package/dist-dev/cloudcmd.common.js +13 -13
  22. package/dist-dev/cloudcmd.css +1 -1
  23. package/dist-dev/cloudcmd.js +3 -3
  24. package/dist-dev/modules/operation.js +1 -1
  25. package/dist-dev/modules/view.js +1 -1
  26. package/dist-dev/sw.js +1 -1
  27. package/package.json +7 -7
  28. package/server/auth.js +2 -2
  29. package/server/cloudcmd.js +4 -19
  30. package/server/columns.js +2 -2
  31. package/server/config.js +9 -6
  32. package/server/distribute/export.js +8 -7
  33. package/server/distribute/import.js +29 -34
  34. package/server/distribute/log.js +0 -1
  35. package/server/env.js +4 -5
  36. package/server/exit.js +0 -1
  37. package/server/markdown/index.js +0 -2
  38. package/server/markdown/worker.js +1 -0
  39. package/server/modulas.js +0 -1
  40. package/server/prefixer.js +0 -1
  41. package/server/repl.js +18 -17
  42. package/server/rest/index.js +8 -5
  43. package/server/rest/info.js +0 -1
  44. package/server/root.js +0 -1
  45. package/server/route.js +11 -15
  46. package/server/server.mjs +3 -9
  47. package/server/show-config.js +6 -2
  48. package/server/template.js +0 -1
  49. package/server/terminal.js +0 -1
  50. package/server/user-menu.js +4 -5
  51. package/server/validate.js +0 -1
  52. package/static/user-menu.js +52 -35
@@ -27,6 +27,7 @@ const {entries} = Object;
27
27
 
28
28
  const equal = (a, b) => `${a}=${b}`;
29
29
  const append = currify((obj, a, b) => obj.value += b && equal(a, b) + '&');
30
+
30
31
  const wrapApply = (f, disconnect) => (status) => () => f(null, {
31
32
  status,
32
33
  disconnect,
@@ -85,6 +86,7 @@ module.exports = (config, options, fn) => {
85
86
  });
86
87
 
87
88
  const url = `${importUrl}/distribute?${query}`;
89
+
88
90
  const socket = io.connect(url, {
89
91
  ...options,
90
92
  rejectUnauthorized: false,
@@ -97,48 +99,42 @@ module.exports = (config, options, fn) => {
97
99
  const statusStore = fullstore();
98
100
  const statusStoreWraped = wraptile(statusStore);
99
101
 
100
- const onConfig = squad(
101
- close,
102
- logWraped(isLog, importStr, `config received from ${colorUrl}`),
103
- statusStoreWraped('received'),
104
- updateConfig(config),
105
- );
102
+ const onConfig = squad(close, logWraped(isLog, importStr, `config received from ${colorUrl}`), statusStoreWraped('received'), updateConfig(config));
106
103
 
107
- const onError = squad(
108
- superFn('error'),
109
- logWraped(isLog, config, importStr),
110
- addUrl(colorUrl),
111
- getMessage,
112
- );
104
+ const onError = squad(superFn('error'), logWraped(isLog, config, importStr), addUrl(colorUrl), getMessage);
113
105
 
114
- const onConnectError = squad(
115
- superFn('connect_error'),
116
- logWraped(isLog, importStr),
117
- addUrl(colorUrl),
118
- getDescription,
119
- );
106
+ const onConnectError = squad(superFn('connect_error'), logWraped(isLog, importStr), addUrl(colorUrl), getDescription);
120
107
 
121
108
  const onConnect = emitAuth(importUrl, config, socket);
122
109
  const onAccept = logWraped(isLog, importStr, `${connectedStr} to ${colorUrl}`);
110
+
123
111
  const onDisconnect = squad(
124
- done(fn, statusStore),
125
- logWraped(isLog, importStr, `${disconnectedStr} from ${colorUrl}`),
126
- rmListeners(socket, {
127
- onError,
128
- onConnect,
129
- onConfig,
130
- }),
112
+ done(
113
+ fn,
114
+ statusStore,
115
+ ),
116
+ logWraped(
117
+ isLog,
118
+ importStr,
119
+ `${disconnectedStr} from ${colorUrl}`,
120
+ ),
121
+ rmListeners(
122
+ socket,
123
+ {
124
+ onError,
125
+ onConnect,
126
+ onConfig,
127
+ },
128
+ ),
131
129
  );
132
130
 
133
- const onChange = squad(
134
- logWraped(isLog, importStr),
135
- config,
136
- );
131
+ const onChange = squad(logWraped(isLog, importStr), config);
137
132
 
138
- const onReject = squad(
139
- superFn('reject'),
140
- logWraped(isLog, importStr, tokenRejectedStr),
141
- );
133
+ const onReject = squad(superFn('reject'), logWraped(
134
+ isLog,
135
+ importStr,
136
+ tokenRejectedStr,
137
+ ));
142
138
 
143
139
  socket.on('connect', onConnect);
144
140
  socket.on('accept', onAccept);
@@ -165,4 +161,3 @@ function toLine(obj) {
165
161
 
166
162
  return result.value.slice(start, backward * end);
167
163
  }
168
-
@@ -39,4 +39,3 @@ function crc(a) {
39
39
  .split('')
40
40
  .reduce(add, 0);
41
41
  }
42
-
package/server/env.js CHANGED
@@ -8,16 +8,16 @@ const up = (a) => a.toUpperCase();
8
8
  module.exports = parse;
9
9
  module.exports.bool = (name) => {
10
10
  const value = parse(name);
11
-
11
+
12
12
  if (value === 'true')
13
13
  return true;
14
-
14
+
15
15
  if (value === '1')
16
16
  return true;
17
-
17
+
18
18
  if (value === 'false')
19
19
  return false;
20
-
20
+
21
21
  if (value === '0')
22
22
  return false;
23
23
  };
@@ -28,4 +28,3 @@ function parse(name) {
28
28
 
29
29
  return env[big] || env[small];
30
30
  }
31
-
package/server/exit.js CHANGED
@@ -8,4 +8,3 @@ module.exports = (...args) => {
8
8
  console.error(...messages);
9
9
  process.exit(1);
10
10
  };
11
-
@@ -13,7 +13,6 @@ const root = require('../root');
13
13
  const parse = threadIt(join(__dirname, 'worker'));
14
14
 
15
15
  threadIt.init();
16
-
17
16
  // warm up
18
17
  parse('');
19
18
 
@@ -63,4 +62,3 @@ function check(name, request) {
63
62
  if (!request)
64
63
  throw Error('request could not be empty!');
65
64
  }
66
-
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
2
 
3
3
  const markdownIt = require('markdown-it')();
4
+
4
5
  module.exports = (a) => markdownIt.render(a);
package/server/modulas.js CHANGED
@@ -13,4 +13,3 @@ module.exports = (modules) => {
13
13
  res.send(result);
14
14
  };
15
15
  };
16
-
@@ -12,4 +12,3 @@ module.exports = (value) => {
12
12
 
13
13
  return value;
14
14
  };
15
-
package/server/repl.js CHANGED
@@ -3,23 +3,24 @@
3
3
  const net = require('net');
4
4
  const repl = require('repl');
5
5
 
6
- module.exports = net.createServer((socket) => {
7
- const {pid} = process;
8
- const addr = socket.remoteAddress;
9
- const port = socket.remotePort;
6
+ module.exports = net
7
+ .createServer((socket) => {
8
+ const {pid} = process;
9
+ const addr = socket.remoteAddress;
10
+ const port = socket.remotePort;
10
11
 
11
- const r = repl.start({
12
- prompt: `[${pid} ${addr}:${port}>`,
13
- input: socket,
14
- output: socket,
15
- terminal: true,
16
- useGlobal: false,
17
- });
12
+ const r = repl.start({
13
+ prompt: `[${pid} ${addr}:${port}>`,
14
+ input: socket,
15
+ output: socket,
16
+ terminal: true,
17
+ useGlobal: false,
18
+ });
18
19
 
19
- r.on('exit', () => {
20
- socket.end();
21
- });
20
+ r.on('exit', () => {
21
+ socket.end();
22
+ });
22
23
 
23
- r.context.socket = socket;
24
- }).listen(1337);
25
-
24
+ r.context.socket = socket;
25
+ })
26
+ .listen(1337);
@@ -29,6 +29,7 @@ const {apiURL} = CloudFunc;
29
29
 
30
30
  const UserError = (msg) => {
31
31
  const error = Error(msg);
32
+
32
33
  error.code = 'EUSER';
33
34
 
34
35
  return error;
@@ -147,7 +148,7 @@ function onGET(params, config, callback) {
147
148
  function getPackReg(packer) {
148
149
  if (packer === 'zip')
149
150
  return /\.zip$/;
150
-
151
+
151
152
  return /\.tar\.gz$/;
152
153
  }
153
154
 
@@ -155,6 +156,7 @@ function streamPack(cmd, response, packer) {
155
156
  const noop = () => {};
156
157
  const filename = cmd.replace(getPackReg(packer), '');
157
158
  const dir = path.dirname(filename);
159
+
158
160
  const names = [
159
161
  path.basename(filename),
160
162
  ];
@@ -165,7 +167,7 @@ function streamPack(cmd, response, packer) {
165
167
  function getCMD(cmd) {
166
168
  if (cmd[0] === '/')
167
169
  return cmd.slice(1);
168
-
170
+
169
171
  return cmd;
170
172
  }
171
173
 
@@ -217,7 +219,9 @@ function onPUT({name, config, body}, callback) {
217
219
  return moveFiles(fromRooted, toRooted, names)
218
220
  .on('error', fn)
219
221
  .on('end', fn);
220
- } case 'rename':
222
+ }
223
+
224
+ case 'rename':
221
225
  return rename(rootDir, files.from, files.to, callback);
222
226
 
223
227
  case 'copy':
@@ -329,7 +333,7 @@ function operation(op, packer, from, to, names, fn) {
329
333
 
330
334
  const [name] = names;
331
335
  pack.on('progress', (count) => {
332
- process.stdout.write(`\r${ op } "${ name }": ${ count }%`);
336
+ process.stdout.write(`\r${op} "${name}": ${count}%`);
333
337
  });
334
338
 
335
339
  pack.on('end', () => {
@@ -403,4 +407,3 @@ function checkPut(name, body, callback) {
403
407
  if (typeof callback !== 'function')
404
408
  throw Error('callback should be a function!');
405
409
  }
406
-
@@ -14,4 +14,3 @@ module.exports = (prefix) => ({
14
14
  prefix,
15
15
  memory: getMemory(),
16
16
  });
17
-
package/server/root.js CHANGED
@@ -5,4 +5,3 @@ const mellow = require('mellow');
5
5
  module.exports = (dir, root) => {
6
6
  return mellow.webToWin(dir, root || '/');
7
7
  };
8
-
package/server/route.js CHANGED
@@ -57,8 +57,12 @@ module.exports = currify((config, options, request, response, next) => {
57
57
  if (!isFS)
58
58
  return next();
59
59
 
60
- route({config, options, request, response})
61
- .catch(next);
60
+ route({
61
+ config,
62
+ options,
63
+ request,
64
+ response,
65
+ }).catch(next);
62
66
  });
63
67
 
64
68
  module.exports._getReadDir = getReadDir;
@@ -102,10 +106,7 @@ async function route({config, options, request, response}) {
102
106
  response.setHeader('Content-Length', contentLength);
103
107
  response.setHeader('Content-Type', contentType(extname(fullPath)));
104
108
 
105
- await pipe([
106
- stream,
107
- response,
108
- ]);
109
+ await pipe([stream, response]);
109
110
  }
110
111
 
111
112
  /**
@@ -131,20 +132,16 @@ function indexProcessing(config, options) {
131
132
  .replace('icon-copy', 'icon-copy none');
132
133
 
133
134
  if (noContact)
134
- data = data
135
- .replace('icon-contact', 'icon-contact none');
135
+ data = data.replace('icon-contact', 'icon-contact none');
136
136
 
137
137
  if (noConfig)
138
- data = data
139
- .replace('icon-config', 'icon-config none');
138
+ data = data.replace('icon-config', 'icon-config none');
140
139
 
141
140
  if (noConsole)
142
- data = data
143
- .replace('icon-console', 'icon-console none');
141
+ data = data.replace('icon-console', 'icon-console none');
144
142
 
145
143
  if (noTerminal)
146
- data = data
147
- .replace('icon-terminal', 'icon-terminal none');
144
+ data = data.replace('icon-terminal', 'icon-terminal none');
148
145
 
149
146
  const left = rendy(Template.panel, {
150
147
  side: 'left',
@@ -204,4 +201,3 @@ function hideKeysPanel(html) {
204
201
 
205
202
  return html.replace(RegExp(from), to);
206
203
  }
207
-
package/server/server.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import cloudcmd from './cloudcmd.js';
2
-
3
2
  import http from 'http';
4
3
  import {promisify} from 'util';
5
4
  import currify from 'currify';
@@ -8,10 +7,8 @@ import tryToCatch from 'try-to-catch';
8
7
  import wraptile from 'wraptile';
9
8
  import compression from 'compression';
10
9
  import threadIt from 'thread-it';
11
-
12
10
  import exit from './exit.js';
13
11
  import opn from 'open';
14
-
15
12
  import express from 'express';
16
13
  import {Server} from 'socket.io';
17
14
  import tryRequire from 'tryrequire';
@@ -25,6 +22,7 @@ const shutdown = wraptile(async (promises) => {
25
22
  threadIt.terminate();
26
23
  process.exit(0);
27
24
  });
25
+
28
26
  const promisifySelf = squad(promisify, bind);
29
27
 
30
28
  const exitPort = two(exit, 'cloudcmd --port: %s');
@@ -32,12 +30,9 @@ const logger = tryRequire('morgan');
32
30
 
33
31
  export default async (options, config) => {
34
32
  const prefix = config('prefix');
35
- const port = process.env.PORT /* c9 */
36
- || config('port');
33
+ const port = process.env.PORT /* c9 */ || config('port');
37
34
 
38
- const ip = process.env.IP /* c9 */
39
- || config('ip')
40
- || '0.0.0.0';
35
+ const ip = process.env.IP /* c9 */ || config('ip') || '0.0.0.0';
41
36
 
42
37
  const app = express();
43
38
  const server = http.createServer(app);
@@ -87,4 +82,3 @@ export default async (options, config) => {
87
82
  if (openError)
88
83
  console.error('cloudcmd --open:', openError.message);
89
84
  };
90
-
@@ -8,7 +8,12 @@ const {
8
8
  module.exports = (config) => {
9
9
  check(config);
10
10
 
11
- const data = Object.keys(config).map((name) => [name, config[name]]);
11
+ const data = Object
12
+ .keys(config)
13
+ .map((name) => [
14
+ name,
15
+ config[name],
16
+ ]);
12
17
 
13
18
  if (!data.length)
14
19
  return '';
@@ -31,4 +36,3 @@ function check(config) {
31
36
  if (typeof config !== 'object')
32
37
  throw Error('config should be an object!');
33
38
  }
34
-
@@ -5,4 +5,3 @@ const readFilesSync = require('@cloudcmd/read-files-sync');
5
5
  const templatePath = path.join(__dirname, '..', 'tmpl/fs');
6
6
 
7
7
  module.exports = readFilesSync(templatePath, 'utf8');
8
-
@@ -25,4 +25,3 @@ module.exports = (config, arg) => {
25
25
 
26
26
  return noop;
27
27
  };
28
-
@@ -13,7 +13,6 @@ const {codeframe} = require('putout');
13
13
  const putout = threadIt(require.resolve('putout'));
14
14
 
15
15
  threadIt.init();
16
-
17
16
  // warm up worker cache
18
17
  transpile('');
19
18
 
@@ -44,9 +43,10 @@ async function onGET({req, res, menuName}) {
44
43
  return sendDefaultMenu(res);
45
44
 
46
45
  const {findUp} = await import('find-up');
47
- const [errorFind, currentMenuPath] = await tryToCatch(findUp, [
48
- menuName,
49
- ], {cwd: dir});
46
+
47
+ const [errorFind, currentMenuPath] = await tryToCatch(findUp, [menuName], {
48
+ cwd: dir,
49
+ });
50
50
 
51
51
  if (errorFind && errorFind.code !== 'ENOENT')
52
52
  return res
@@ -106,4 +106,3 @@ async function transpile(source) {
106
106
  ],
107
107
  });
108
108
  }
109
-
@@ -50,4 +50,3 @@ module.exports.columns = (type) => {
50
50
  if (!all.includes(type))
51
51
  exit(`cloudcmd --columns: can be only one of: ${names}`);
52
52
  };
53
-
@@ -5,61 +5,79 @@ const CDN = 'https://cdn.jsdelivr.net/gh/cloudcmd/user-menu@1.2.4';
5
5
 
6
6
  module.exports = {
7
7
  '__settings': {
8
- select: [
9
- RENAME_FILE,
10
- ],
8
+ select: [RENAME_FILE],
11
9
  run: false,
12
10
  },
13
11
  [`F2 - ${RENAME_FILE}`]: async ({DOM}) => {
14
12
  await DOM.renameCurrent();
15
13
  },
16
-
14
+
17
15
  'F6 - Copy URL to current file': async ({DOM}) => {
18
16
  const {copyURLToCurrentFile} = await import(`${CDN}/menu/copy-url-to-current-file.js`);
19
- await copyURLToCurrentFile({DOM});
17
+
18
+ await copyURLToCurrentFile({
19
+ DOM,
20
+ });
20
21
  },
21
-
22
+
22
23
  'R - cd /': async ({CloudCmd}) => {
23
24
  await CloudCmd.changeDir('/');
24
25
  },
25
26
  'Y - Convert YouTube to MP3': async ({CloudCmd, DOM}) => {
26
27
  const {convertYouTubeToMp3} = await import(`${CDN}/menu/convert-youtube-to-mp3.js`);
27
- await convertYouTubeToMp3({CloudCmd, DOM});
28
+
29
+ await convertYouTubeToMp3({
30
+ CloudCmd,
31
+ DOM,
32
+ });
28
33
  },
29
-
34
+
30
35
  'F - Convert flac to mp3 [ffmpeg]': async ({CloudCmd, DOM}) => {
31
36
  const {convertFlacToMp3} = await import(`${CDN}/menu/ffmpeg.js`);
32
- await convertFlacToMp3({CloudCmd, DOM});
37
+
38
+ await convertFlacToMp3({
39
+ CloudCmd,
40
+ DOM,
41
+ });
33
42
  },
34
43
  'M - Convert mp4 to mp3 [ffmpeg]': async ({CloudCmd, DOM}) => {
35
44
  const {convertMp4ToMp3} = await import(`${CDN}/menu/ffmpeg.js`);
36
- await convertMp4ToMp3({CloudCmd, DOM});
45
+
46
+ await convertMp4ToMp3({
47
+ CloudCmd,
48
+ DOM,
49
+ });
37
50
  },
38
-
51
+
39
52
  'O - Convert mov to mp3 [ffmpeg]': async ({CloudCmd, DOM}) => {
40
53
  const {convertMovToMp3} = await import(`${CDN}/menu/ffmpeg.js`);
41
- await convertMovToMp3({CloudCmd, DOM});
54
+
55
+ await convertMovToMp3({
56
+ CloudCmd,
57
+ DOM,
58
+ });
42
59
  },
43
-
60
+
44
61
  'C - Create User Menu File': async ({DOM, CloudCmd}) => {
45
- const {
46
- Dialog,
47
- CurrentInfo,
48
- } = DOM;
62
+ const {Dialog, CurrentInfo} = DOM;
63
+
49
64
  const currentFile = DOM.getCurrentByName('.cloudcmd.menu.js');
50
-
65
+
51
66
  if (currentFile) {
52
67
  const [cancel] = await Dialog.confirm(`Looks like file '.cloudcmd.menu.js' already exists. Overwrite?`);
53
-
68
+
54
69
  if (cancel)
55
70
  return;
56
71
  }
57
-
72
+
58
73
  const {dirPath} = CurrentInfo;
59
74
  const path = `${dirPath}.cloudcmd.menu.js`;
60
75
  const {prefix} = CloudCmd;
61
-
62
- const data = await readDefaultMenu({prefix});
76
+
77
+ const data = await readDefaultMenu({
78
+ prefix,
79
+ });
80
+
63
81
  await createDefaultMenu({
64
82
  path,
65
83
  data,
@@ -74,25 +92,25 @@ module.exports = {
74
92
  getCurrentByName,
75
93
  selectFile,
76
94
  } = DOM;
77
-
95
+
78
96
  const {
79
97
  files,
80
98
  filesPassive,
81
99
  panel,
82
100
  panelPassive,
83
101
  } = CurrentInfo;
84
-
102
+
85
103
  const names = getFilenames(files);
86
104
  const namesPassive = getFilenames(filesPassive);
87
-
105
+
88
106
  const selectedNames = compare(names, namesPassive);
89
107
  const selectedNamesPassive = compare(namesPassive, names);
90
-
108
+
91
109
  selectNames(selectedNames, panel, {
92
110
  selectFile,
93
111
  getCurrentByName,
94
112
  });
95
-
113
+
96
114
  selectNames(selectedNamesPassive, panelPassive, {
97
115
  selectFile,
98
116
  getCurrentByName,
@@ -102,19 +120,19 @@ module.exports = {
102
120
 
103
121
  async function createDefaultMenu({path, data, DOM, CloudCmd}) {
104
122
  const {IO} = DOM;
105
-
123
+
106
124
  await IO.write(path, data);
107
125
  await CloudCmd.refresh();
108
-
126
+
109
127
  DOM.setCurrentByName('.cloudcmd.menu.js');
110
-
128
+
111
129
  await CloudCmd.EditFile.show();
112
130
  }
113
131
 
114
132
  async function readDefaultMenu({prefix}) {
115
133
  const res = await fetch(`${prefix}/api/v1/user-menu/default`);
116
134
  const data = await res.text();
117
-
135
+
118
136
  return data;
119
137
  }
120
138
 
@@ -129,14 +147,13 @@ function selectNames(names, panel, {selectFile, getCurrentByName}) {
129
147
  module.exports._compare = compare;
130
148
  function compare(a, b) {
131
149
  const result = [];
132
-
150
+
133
151
  for (const el of a) {
134
152
  if (b.includes(el))
135
153
  continue;
136
-
154
+
137
155
  result.push(el);
138
156
  }
139
-
157
+
140
158
  return result;
141
159
  }
142
-