nestjs-web-console 1.0.1 → 1.0.3

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 (47) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +66 -66
  3. package/dist/console.types.d.ts +75 -75
  4. package/dist/console.types.js +15 -15
  5. package/dist/controllers/web.console.controller.d.ts +1 -1
  6. package/dist/controllers/web.console.controller.js +690 -675
  7. package/dist/filters/http-exception.filter.d.ts +4 -4
  8. package/dist/filters/http-exception.filter.js +50 -50
  9. package/dist/index.d.ts +8 -8
  10. package/dist/index.js +24 -24
  11. package/dist/services/all.commands.d.ts +3 -3
  12. package/dist/services/all.commands.js +13 -13
  13. package/dist/services/processors/base/console.command.d.ts +8 -8
  14. package/dist/services/processors/base/console.command.js +27 -27
  15. package/dist/services/processors/base/invalid.command.d.ts +5 -5
  16. package/dist/services/processors/base/invalid.command.js +14 -14
  17. package/dist/services/processors/base/not-logged.command.d.ts +5 -5
  18. package/dist/services/processors/base/not-logged.command.js +10 -10
  19. package/dist/services/processors/bash.command.d.ts +7 -7
  20. package/dist/services/processors/bash.command.js +102 -102
  21. package/dist/services/processors/clear-screen.command.d.ts +6 -6
  22. package/dist/services/processors/clear-screen.command.js +30 -30
  23. package/dist/services/processors/cmd.command.d.ts +7 -7
  24. package/dist/services/processors/cmd.command.js +99 -99
  25. package/dist/services/processors/help.command.d.ts +7 -7
  26. package/dist/services/processors/help.command.js +41 -41
  27. package/dist/services/processors/index.d.ts +8 -8
  28. package/dist/services/processors/index.js +24 -24
  29. package/dist/services/processors/invite.command.d.ts +9 -9
  30. package/dist/services/processors/invite.command.js +76 -76
  31. package/dist/services/processors/join.command.d.ts +8 -8
  32. package/dist/services/processors/join.command.js +108 -108
  33. package/dist/services/processors/login.command.d.ts +14 -14
  34. package/dist/services/processors/login.command.js +69 -69
  35. package/dist/services/processors/logout.command.d.ts +6 -6
  36. package/dist/services/processors/logout.command.js +30 -30
  37. package/dist/services/remote.console.service.d.ts +30 -30
  38. package/dist/services/remote.console.service.js +107 -107
  39. package/dist/services/temp.file.service.d.ts +25 -23
  40. package/dist/services/temp.file.service.js +102 -90
  41. package/dist/services/web.console.service.d.ts +57 -57
  42. package/dist/services/web.console.service.js +437 -437
  43. package/dist/web.console.module.d.ts +6 -6
  44. package/dist/web.console.module.js +87 -87
  45. package/dist.zip +0 -0
  46. package/package.json +5 -5
  47. package/tsconfig.json +18 -18
@@ -1,675 +1,690 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- var __importDefault = (this && this.__importDefault) || function (mod) {
15
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
- };
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.WebConsoleControllerFactory = void 0;
19
- const common_1 = require("@nestjs/common");
20
- const ejs_1 = __importDefault(require("ejs"));
21
- const express_1 = __importDefault(require("express"));
22
- const http_exception_filter_1 = require("../filters/http-exception.filter");
23
- const remote_console_service_1 = require("../services/remote.console.service");
24
- const temp_file_service_1 = require("../services/temp.file.service");
25
- const web_console_service_1 = require("../services/web.console.service");
26
- const boot = new Date();
27
- function WebConsoleControllerFactory(endpoint) {
28
- let WebConsoleController = class WebConsoleController {
29
- constructor(webConsoleService, remoteConsoleService, tempFileService) {
30
- Object.defineProperty(this, "webConsoleService", {
31
- enumerable: true,
32
- configurable: true,
33
- writable: true,
34
- value: webConsoleService
35
- });
36
- Object.defineProperty(this, "remoteConsoleService", {
37
- enumerable: true,
38
- configurable: true,
39
- writable: true,
40
- value: remoteConsoleService
41
- });
42
- Object.defineProperty(this, "tempFileService", {
43
- enumerable: true,
44
- configurable: true,
45
- writable: true,
46
- value: tempFileService
47
- });
48
- Object.defineProperty(this, "consoleOptions", {
49
- enumerable: true,
50
- configurable: true,
51
- writable: true,
52
- value: void 0
53
- });
54
- Object.defineProperty(this, "view", {
55
- enumerable: true,
56
- configurable: true,
57
- writable: true,
58
- value: `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
59
- <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
60
- <head>
61
- <title>Web Console | <%= model.name %></title>
62
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
63
- <meta name="robots" content="noindex">
64
- <style type="text/css">
65
- * {
66
- margin: 0;
67
- padding: 0;
68
- }
69
-
70
- html, body {
71
- height: 100%;
72
- }
73
-
74
- body {
75
- background: black;
76
- color: white;
77
- font-family: Consolas, Monaco, monospace;
78
- font-size: 0;
79
- display: flex;
80
- flex-direction: column;
81
- transition: opacity 500ms;
82
- }
83
-
84
- div#output {
85
- overflow-y: auto;
86
- overflow-x: hidden;
87
- padding: 5px;
88
- font-size: 14px;
89
- flex: 1;
90
- }
91
-
92
- div#bottom, div#bottom-base {
93
- font-size: 14px;
94
- display: flex;
95
- }
96
-
97
- div#bottom-base {
98
- padding: 10px 0;
99
- }
100
-
101
- div#bottom-base > * {
102
- margin-left: 10px;
103
- }
104
-
105
- span#input {
106
- flex: 1;
107
- display: flex;
108
- }
109
-
110
- input, input:focus, input:active input:focus-visible {
111
- font-family: Consolas, Monaco, monospace;
112
- background: transparent;
113
- border: none;
114
- outline: none;
115
- color: white;
116
- font-size: 14px;
117
- flex: 1;
118
- }
119
-
120
- input:-webkit-autofill,
121
- input:-webkit-autofill:hover,
122
- input:-webkit-autofill:focus,
123
- input:-webkit-autofill:active {
124
- -webkit-box-shadow: 0 0 0 30px black inset !important;
125
- }
126
-
127
- input:-webkit-autofill {
128
- -webkit-text-fill-color: white !important;
129
- font-family: Consolas, Monaco, monospace;
130
- font-size: 14px;
131
- }
132
-
133
- div.row {
134
- display: flex;
135
- }
136
-
137
- select {
138
- -webkit-appearance: none;
139
- -moz-appearance: none;
140
- appearance: none;
141
- background-color: black;
142
- border: none;
143
- padding: 0 1em 0 0;
144
- margin: 0;
145
- width: 100%;
146
- font-family: inherit;
147
- font-size: inherit;
148
- cursor: inherit;
149
- line-height: inherit;
150
- color: white;
151
- z-index: 1;
152
- outline: none;
153
- overflow: hidden;
154
- }
155
-
156
- select::-ms-expand {
157
- display: none;
158
- }
159
-
160
- .select {
161
- display: grid;
162
- grid-template-areas: "select";
163
- align-items: center;
164
- position: relative;
165
- min-width: 15ch;
166
- max-width: unset;
167
- border: 0;
168
- border-radius: 0.25em;
169
- cursor: pointer;
170
- background-color: #000;
171
- background-image: linear-gradient(to top, #000, #000 33%);
172
- }
173
-
174
- .select select, .select::after {
175
- grid-area: select;
176
- }
177
-
178
- .select:not(.select--multiple)::after {
179
- content: "";
180
- justify-self: end;
181
- width: 0.6em;
182
- height: 0.35em;
183
- z-index: 1;
184
- background-color: white;
185
- -webkit-clip-path: polygon(100% 0%, 0 0%, 50% 100%);
186
- clip-path: polygon(100% 0%, 0 0%, 50% 100%);
187
- }
188
-
189
- .select.desktop:not(.select--multiple)::after {
190
- content: none;
191
- }
192
-
193
- .desktop-hide {
194
- display: none !important;
195
- }
196
-
197
- .submitting {
198
- pointer-events: none;
199
- touch-action: none;
200
- }
201
-
202
- .submitting2 {
203
- opacity: 0.7;
204
- }
205
-
206
- select:focus + .focus {
207
- position: absolute;
208
- top: -1px;
209
- left: -1px;
210
- right: -1px;
211
- bottom: -1px;
212
- border: 0;
213
- border-radius: inherit;
214
- }
215
-
216
- </style>
217
- <script src="https://code.jquery.com/jquery-3.6.0.slim.min.js"></script>
218
- </head>
219
- <body>
220
- <div id="output">
221
- <div>
222
- Web Console | <%= model.name %><br />
223
- All rights reserved.<br /><br />
224
- Server boot: <%= model.boot %><br /><br />
225
- </div>
226
- <div id="logs">
227
- <%- model.result %>
228
-
229
- <% if (model.running && model.readLine) { %>
230
- <form method="post" style="display: flex; flex: 1" class="commandFormInline">
231
- <% if (model.readLineOpts.select) { %>
232
- <div class="select">
233
- <select id="command" name="command" size="<%= Math.max(2,model.readLineOpts.select.length) %>"
234
- autofocus="autofocus">
235
- <option value="[null]" id="empty">Select...</option>
236
- <% model.readLineOpts.select.forEach(function(x, i) {
237
- const isArray = Array.isArray(x);
238
- %>
239
- <option value="<%= isArray ? x[0] : x %>"><%= isArray ? x[1] : x %></option>
240
- <% }) %>
241
- </select>
242
- <span class="focus"></span>
243
- </div>
244
- <% } else { %>
245
- <input type="<%= model.readLineOpts.secure ? 'password' : 'text' %>" id="command" name="command" style="flex: 1"
246
- autofocus="autofocus" autocomplete="off" />
247
- <% } %>
248
- </form><%- '</div>' %>
249
- <% } %>
250
- </div>
251
- <div id="running"></div>
252
-
253
- <form method="post" class="commandForm">
254
- <div id="bottom">
255
- <% if (!model.running) { %>
256
- <span id="path">web:/&gt;&nbsp;</span>
257
- <span id="input"><input type="text" id="command" name="command" autofocus="autofocus" autocomplete="off" /></span>
258
- <% } %>
259
- </div>
260
- </form>
261
-
262
- <form method="post" id="cancelForm">
263
- <input type="hidden" name="command" value="ctrl+c" />
264
- </form>
265
- <form method="post" id="cancelShiftForm">
266
- <input type="hidden" name="command" value="ctrl+shift+c" />
267
- </form>
268
- </div>
269
- <div id="bottom-base">
270
- <% if (model.running) { %>
271
- <div id="cancel">[ Terminate ]</div>
272
- <div id="shiftCancel">[ Cancel Signal ]</div>
273
- <% } else { %>
274
- <div id="prev">[ Previous ]</div>
275
- <div id="next">[ Next ]</div>
276
- <% } %>
277
- </div>
278
- <script type="text/javascript">
279
- document.getElementById('bottom').scrollIntoView(false);
280
- const commands = JSON.parse(localStorage.getItem('command-history') || '[]');
281
- const commandStore = {
282
- index: commands.length,
283
- commandCount: commands.length,
284
- prevCommand: commands,
285
- put: function (val) {
286
- if (!val)
287
- return;
288
- if (this.prevCommand.indexOf(val) > -1) {
289
- this.prevCommand = this.prevCommand.filter(x => x != val);
290
- this.commandCount = this.prevCommand.length;
291
- }
292
- this.commandCount++;
293
- this.index = this.commandCount;
294
- this.prevCommand.push(val);
295
- if (this.commandCount > 30) {
296
- this.prevCommand.shift();
297
- this.commandCount = this.prevCommand.length;
298
- this.index = this.commandCount;
299
- }
300
- localStorage.setItem('command-history', JSON.stringify(this.prevCommand));
301
- },
302
- get: function (isUp) {
303
- if (isUp && this.index > 0)
304
- this.index--;
305
- else if (!isUp && this.index < this.commandCount)
306
- this.index++;
307
- if (typeof this.prevCommand[this.index] !== "undefined") {
308
- return this.prevCommand[this.index];
309
- }
310
- return '';
311
- }
312
-
313
- }
314
- </script>
315
- <script type="text/javascript">
316
- $(document).on('keydown', function (e) {
317
- e = e || window.event;
318
- const key = e.which || e.keyCode;
319
- const ctrl = e.ctrlKey ? e.ctrlKey : ((key === 17) ? true : false);
320
- const shift = e.shiftKey ? e.shiftKey : ((key === 16) ? true : false);
321
- const alt = e.altKey ? e.altKey : ((key === 18) ? true : false);
322
-
323
- <% if (model.running) { %>
324
-
325
- if (key === 67 && alt && shift) {
326
- $('#cancelShiftForm').submit();
327
- } else if (key === 67 && alt) {
328
- $('#cancelForm').submit();
329
- }
330
- <% } else { %>
331
-
332
- if (key === 38 && $("input").is(":focus")) {
333
- const val = commandStore.get(true);
334
- $("input").val(val);
335
- const input = $("input")[0];
336
- setTimeout(function () { input.selectionStart = input.selectionEnd = input.value.length; }, 0);
337
- } else if (key === 40 && $("input").is(":focus")) {
338
- const val = commandStore.get(false);
339
- $("input").val(val);
340
- const input = $("input")[0];
341
- setTimeout(function () { input.selectionStart = input.selectionEnd = input.value.length; }, 0);
342
- }
343
- <% } %>
344
-
345
- if (key === 13 && $("select").is(":focus")) {
346
- $('form.commandFormInline').submit();
347
- }
348
- });
349
-
350
- <% if (!model.readLine) { %>
351
- $("form.commandForm").on("submit", function (e) {
352
- commandStore.put($('input').val());
353
- });
354
- <% } %>
355
-
356
- <% if (model.running && !model.readLine) { %>
357
- let start = +'<%= model.result.length %>';
358
- setInterval(() => {
359
- fetch('/console/substring/' + start).then(x => x.json())
360
- .then(x => {
361
- if (!x.running || x.readLine)
362
- window.location.href = '/console';
363
- else if (x.result.length) {
364
- $('#logs').append(x.result);
365
- start += x.result.length;
366
- document.getElementById('bottom').scrollIntoView(false);
367
- }
368
- });
369
- }, 1000);
370
- let ticks = 1;
371
- setInterval(() => {
372
- $('#running').html('.'.repeat(ticks++));
373
- if (ticks > 3)
374
- ticks = 1;
375
- }, 300);
376
- <% } %>
377
- if (window.history.replaceState) {
378
- window.history.replaceState(null, null, window.location.href);
379
- }
380
- const isMobile = (navigator.maxTouchPoints || 'ontouchstart' in document.documentElement);
381
-
382
- <% if (model.readLine && model.readLineOpts.select) { %>
383
- if (isMobile) {
384
- $('select').on('change', function () {
385
- if ($(this).val() !== '[null]')
386
- $('form.commandFormInline').submit();
387
- });
388
- $('select').attr('size', 1);
389
- } else {
390
- $('select > option').first().remove();
391
- $('.select').addClass('desktop');
392
- }
393
- $('select')[0].selectedIndex = 0;
394
- <% } %>
395
- if (!isMobile) {
396
- $('#bottom-base').addClass('desktop-hide');
397
- }
398
- <% if (model.running) { %>
399
- if (isMobile) {
400
- $('#cancel').on('click', function () {
401
- $('#cancelForm').submit();
402
- });
403
- $('#shiftCancel').on('click', function () {
404
- $('#cancelShiftForm').submit();
405
- });
406
- }
407
- <% } else { %>
408
-
409
- if (isMobile) {
410
- $('#prev').on('click', function () {
411
- const val = commandStore.get(true);
412
- $("input").val(val);
413
- const input = $("input")[0];
414
- setTimeout(function () { input.selectionStart = input.selectionEnd = input.value.length; }, 0);
415
- });
416
- $('#next').on('click', function () {
417
- const val = commandStore.get(false);
418
- $("input").val(val);
419
- const input = $("input")[0];
420
- setTimeout(function () { input.selectionStart = input.selectionEnd = input.value.length; }, 0);
421
- });
422
- }
423
- <% } %>
424
- $('form').on('submit', function () {
425
- document.activeElement?.blur();
426
- $('body').addClass('submitting submitting2');
427
- });
428
-
429
- var longpress = false;
430
-
431
- $("body").on('click', function () {
432
- if (!longpress)
433
- document.getElementById('command')?.focus();
434
- });
435
-
436
- var startTime, endTime;
437
- $("body").on('mousedown', function () {
438
- startTime = new Date().getTime();
439
- });
440
-
441
- $("body").on('mouseup', function () {
442
- endTime = new Date().getTime();
443
- longpress = (endTime - startTime < 500) ? false : true;
444
- });
445
- </script>
446
- </body>
447
- </html>
448
- `
449
- });
450
- }
451
- async getSubstring(req, res, start) {
452
- const session = this.webConsoleService.getSession(req, res);
453
- let result;
454
- if (session.logs.length <= +start)
455
- result = '';
456
- else
457
- result = session.logs.substring(+start);
458
- return res.send({
459
- result,
460
- running: session.running,
461
- readLine: !!session.readLineCallback,
462
- });
463
- }
464
- async get(req, res) {
465
- const session = this.webConsoleService.getSession(req, res);
466
- return res.send(ejs_1.default.render(this.view, {
467
- model: {
468
- name: this.consoleOptions.name,
469
- result: session.logs,
470
- running: session.running,
471
- readLine: !!session.readLineCallback,
472
- readLineOpts: session.readLineOpts,
473
- boot
474
- }
475
- })
476
- .replace(/>[\r\n ]+</g, "><")
477
- .replace(/(<.*?>)|\s+/g, (m, $1) => $1 ? $1 : ' ')
478
- .trim());
479
- }
480
- async post(command, req, res, ip) {
481
- var _a, _b, _c;
482
- if (command == null)
483
- command = '';
484
- const escaped = command.replace(/\\\|/g, '\r\n');
485
- const cmds = escaped.split("|").filter(x => x)
486
- .map(x => x.replace(/\r\n/g, '|'));
487
- const session = this.webConsoleService.getSession(req, res);
488
- if (command == 'ctrl+c') {
489
- session.cancel = true;
490
- (_a = session.onCancel) === null || _a === void 0 ? void 0 : _a.call(this);
491
- if (session.readLineCallback) {
492
- session.readLineCallback(null);
493
- session.logs += '</div>';
494
- session.readLineCallback = null;
495
- }
496
- session.logs += '<div>Operation canceled</div><br/>';
497
- session.running = false;
498
- }
499
- else if (command == 'ctrl+shift+c') {
500
- if (session.onCancelSignal)
501
- (_b = session.onCancelSignal) === null || _b === void 0 ? void 0 : _b.call(this);
502
- else {
503
- session.cancel = true;
504
- (_c = session.onCancel) === null || _c === void 0 ? void 0 : _c.call(this);
505
- if (session.readLineCallback) {
506
- session.readLineCallback(null);
507
- session.logs += '</div>';
508
- session.readLineCallback = null;
509
- }
510
- session.logs += '<div>Operation canceled</div><br/>';
511
- session.running = false;
512
- }
513
- }
514
- else {
515
- if (session.readLineCallback) {
516
- (async () => {
517
- session.readLineCallback(command);
518
- })().catch(e => {
519
- if (session.cancel)
520
- return;
521
- session.logs += e + '<br/><br/>';
522
- session.running = false;
523
- });
524
- session.readLineCallback = null;
525
- }
526
- else {
527
- session.cancel = false;
528
- session.onCancel = null;
529
- session.running = true;
530
- (async () => {
531
- if (!cmds.length) {
532
- session.logs += `web:/> `;
533
- }
534
- for (let i = 0; i < cmds.length; i++) {
535
- let cmd = cmds[i];
536
- const { cmd: parsed, arg } = this.webConsoleService.parse(cmd, session);
537
- await parsed.process({
538
- session,
539
- arg,
540
- req,
541
- res,
542
- ip,
543
- rawCommand: cmd,
544
- log: (...text) => this.webConsoleService.log(session, this.webConsoleService.escapeHtml(text.map(x => typeof x == "object" ? JSON.stringify(x, null, 2) : x).join(' ')).replace(/\n/g, '<br/>').replace(/\r/g, '').replace(/\s\s/g, ' &nbsp;')),
545
- logRaw: (text) => this.webConsoleService.log(session, text),
546
- logTable: (entities, noColumns) => this.webConsoleService.log(session, this.webConsoleService.toTable(entities, noColumns)),
547
- readArgs: (mapList, parameters) => this.webConsoleService.readArgs(session, arg, mapList, parameters),
548
- readLine: (title, opts) => this.webConsoleService.readLine(session, title || '', opts),
549
- parseArgs: (funcArg) => this.webConsoleService.parseArgs(funcArg || arg),
550
- toTable: this.webConsoleService.toTable,
551
- loop: this.webConsoleService.loopFactory(session),
552
- longWork: this.webConsoleService.longWorkFactory(session),
553
- });
554
- }
555
- })().catch(e => {
556
- if (session.cancel)
557
- return;
558
- session.logs += e + '<br/>';
559
- }).finally(() => {
560
- if (session.cancel)
561
- return;
562
- session.logs += '<br/>';
563
- session.running = false;
564
- });
565
- }
566
- }
567
- setImmediate(() => {
568
- res.send(ejs_1.default.render(this.view, {
569
- model: {
570
- name: this.consoleOptions.name,
571
- result: session.logs,
572
- running: session.running,
573
- readLine: !!session.readLineCallback,
574
- readLineOpts: session.readLineOpts,
575
- boot
576
- }
577
- })
578
- .replace(/>[\r\n ]+</g, "><")
579
- .replace(/(<.*?>)|\s+/g, (m, $1) => $1 ? $1 : ' ')
580
- .trim());
581
- });
582
- }
583
- invite(input) {
584
- return this.remoteConsoleService.inviteThisConsole(input.name, input.v, input.p);
585
- }
586
- stream(input) {
587
- return this.remoteConsoleService.pumpStream(input);
588
- }
589
- close(input) {
590
- return this.remoteConsoleService.closeFromRemote(input.name);
591
- }
592
- downloadTemp(name, res) {
593
- const file = this.tempFileService.read(name);
594
- switch (file.type) {
595
- case 'csv':
596
- if (!res['csv'])
597
- throw new common_1.BadRequestException('Module csv-express not installed');
598
- res.charset = 'utf8';
599
- return res['csv'](file.content, true);
600
- case 'html':
601
- res.setHeader('Content-Type', 'text/html');
602
- return res.send(file.content);
603
- }
604
- throw new common_1.BadRequestException(`Invalid file type: ${file.type}`);
605
- }
606
- };
607
- __decorate([
608
- (0, common_1.Inject)('CONFIG_ROOT_OPTIONS'),
609
- __metadata("design:type", Object)
610
- ], WebConsoleController.prototype, "consoleOptions", void 0);
611
- __decorate([
612
- (0, common_1.Get)('substring/:start'),
613
- __param(0, (0, common_1.Req)()),
614
- __param(1, (0, common_1.Res)()),
615
- __param(2, (0, common_1.Param)('start')),
616
- __metadata("design:type", Function),
617
- __metadata("design:paramtypes", [Object, Object, String]),
618
- __metadata("design:returntype", Promise)
619
- ], WebConsoleController.prototype, "getSubstring", null);
620
- __decorate([
621
- (0, common_1.Get)(),
622
- __param(0, (0, common_1.Req)()),
623
- __param(1, (0, common_1.Res)()),
624
- __metadata("design:type", Function),
625
- __metadata("design:paramtypes", [Object, Object]),
626
- __metadata("design:returntype", Promise)
627
- ], WebConsoleController.prototype, "get", null);
628
- __decorate([
629
- (0, common_1.Post)(),
630
- __param(0, (0, common_1.Body)('command')),
631
- __param(1, (0, common_1.Req)()),
632
- __param(2, (0, common_1.Res)()),
633
- __param(3, (0, common_1.Ip)()),
634
- __metadata("design:type", Function),
635
- __metadata("design:paramtypes", [String, Object, Object, String]),
636
- __metadata("design:returntype", Promise)
637
- ], WebConsoleController.prototype, "post", null);
638
- __decorate([
639
- (0, common_1.Get)('remote/invite'),
640
- __param(0, (0, common_1.Query)()),
641
- __metadata("design:type", Function),
642
- __metadata("design:paramtypes", [Object]),
643
- __metadata("design:returntype", void 0)
644
- ], WebConsoleController.prototype, "invite", null);
645
- __decorate([
646
- (0, common_1.Post)('remote/stream'),
647
- __param(0, (0, common_1.Body)()),
648
- __metadata("design:type", Function),
649
- __metadata("design:paramtypes", [Object]),
650
- __metadata("design:returntype", void 0)
651
- ], WebConsoleController.prototype, "stream", null);
652
- __decorate([
653
- (0, common_1.Post)('remote/close'),
654
- __param(0, (0, common_1.Body)()),
655
- __metadata("design:type", Function),
656
- __metadata("design:paramtypes", [Object]),
657
- __metadata("design:returntype", void 0)
658
- ], WebConsoleController.prototype, "close", null);
659
- __decorate([
660
- (0, common_1.Get)('file/:name'),
661
- __param(0, (0, common_1.Param)('name')),
662
- __param(1, (0, common_1.Res)()),
663
- __metadata("design:type", Function),
664
- __metadata("design:paramtypes", [String, Object]),
665
- __metadata("design:returntype", void 0)
666
- ], WebConsoleController.prototype, "downloadTemp", null);
667
- WebConsoleController = __decorate([
668
- (0, common_1.Controller)(endpoint || 'console'),
669
- (0, common_1.UseFilters)(http_exception_filter_1.HttpExceptionFilter),
670
- __metadata("design:paramtypes", [web_console_service_1.WebConsoleService, remote_console_service_1.RemoteConsoleService,
671
- temp_file_service_1.TempFileService])
672
- ], WebConsoleController);
673
- return WebConsoleController;
674
- }
675
- exports.WebConsoleControllerFactory = WebConsoleControllerFactory;
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.WebConsoleControllerFactory = void 0;
19
+ const common_1 = require("@nestjs/common");
20
+ const ejs_1 = __importDefault(require("ejs"));
21
+ const express_1 = __importDefault(require("express"));
22
+ const http_exception_filter_1 = require("../filters/http-exception.filter");
23
+ const remote_console_service_1 = require("../services/remote.console.service");
24
+ const temp_file_service_1 = require("../services/temp.file.service");
25
+ const web_console_service_1 = require("../services/web.console.service");
26
+ const core_1 = require("@nestjs/core");
27
+ const boot = new Date();
28
+ function WebConsoleControllerFactory(endpoint) {
29
+ let WebConsoleController = class WebConsoleController {
30
+ constructor(webConsoleService, remoteConsoleService, tempFileService) {
31
+ Object.defineProperty(this, "webConsoleService", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: webConsoleService
36
+ });
37
+ Object.defineProperty(this, "remoteConsoleService", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: remoteConsoleService
42
+ });
43
+ Object.defineProperty(this, "tempFileService", {
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true,
47
+ value: tempFileService
48
+ });
49
+ Object.defineProperty(this, "consoleOptions", {
50
+ enumerable: true,
51
+ configurable: true,
52
+ writable: true,
53
+ value: void 0
54
+ });
55
+ Object.defineProperty(this, "appConfig", {
56
+ enumerable: true,
57
+ configurable: true,
58
+ writable: true,
59
+ value: void 0
60
+ });
61
+ Object.defineProperty(this, "view", {
62
+ enumerable: true,
63
+ configurable: true,
64
+ writable: true,
65
+ value: `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
66
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
67
+ <head>
68
+ <title>Web Console | <%= model.name %></title>
69
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
70
+ <meta name="robots" content="noindex">
71
+ <style type="text/css">
72
+ * {
73
+ margin: 0;
74
+ padding: 0;
75
+ }
76
+
77
+ html, body {
78
+ height: 100%;
79
+ }
80
+
81
+ body {
82
+ background: black;
83
+ color: white;
84
+ font-family: Consolas, Monaco, monospace;
85
+ font-size: 0;
86
+ display: flex;
87
+ flex-direction: column;
88
+ transition: opacity 500ms;
89
+ }
90
+
91
+ div#output {
92
+ overflow-y: auto;
93
+ overflow-x: hidden;
94
+ padding: 5px;
95
+ font-size: 14px;
96
+ flex: 1;
97
+ }
98
+
99
+ div#bottom, div#bottom-base {
100
+ font-size: 14px;
101
+ display: flex;
102
+ }
103
+
104
+ div#bottom-base {
105
+ padding: 10px 0;
106
+ }
107
+
108
+ div#bottom-base > * {
109
+ margin-left: 10px;
110
+ }
111
+
112
+ span#input {
113
+ flex: 1;
114
+ display: flex;
115
+ }
116
+
117
+ input, input:focus, input:active input:focus-visible {
118
+ font-family: Consolas, Monaco, monospace;
119
+ background: transparent;
120
+ border: none;
121
+ outline: none;
122
+ color: white;
123
+ font-size: 14px;
124
+ flex: 1;
125
+ }
126
+
127
+ input:-webkit-autofill,
128
+ input:-webkit-autofill:hover,
129
+ input:-webkit-autofill:focus,
130
+ input:-webkit-autofill:active {
131
+ -webkit-box-shadow: 0 0 0 30px black inset !important;
132
+ }
133
+
134
+ input:-webkit-autofill {
135
+ -webkit-text-fill-color: white !important;
136
+ font-family: Consolas, Monaco, monospace;
137
+ font-size: 14px;
138
+ }
139
+
140
+ div.row {
141
+ display: flex;
142
+ }
143
+
144
+ select {
145
+ -webkit-appearance: none;
146
+ -moz-appearance: none;
147
+ appearance: none;
148
+ background-color: black;
149
+ border: none;
150
+ padding: 0 1em 0 0;
151
+ margin: 0;
152
+ width: 100%;
153
+ font-family: inherit;
154
+ font-size: inherit;
155
+ cursor: inherit;
156
+ line-height: inherit;
157
+ color: white;
158
+ z-index: 1;
159
+ outline: none;
160
+ overflow: hidden;
161
+ }
162
+
163
+ select::-ms-expand {
164
+ display: none;
165
+ }
166
+
167
+ .select {
168
+ display: grid;
169
+ grid-template-areas: "select";
170
+ align-items: center;
171
+ position: relative;
172
+ min-width: 15ch;
173
+ max-width: unset;
174
+ border: 0;
175
+ border-radius: 0.25em;
176
+ cursor: pointer;
177
+ background-color: #000;
178
+ background-image: linear-gradient(to top, #000, #000 33%);
179
+ }
180
+
181
+ .select select, .select::after {
182
+ grid-area: select;
183
+ }
184
+
185
+ .select:not(.select--multiple)::after {
186
+ content: "";
187
+ justify-self: end;
188
+ width: 0.6em;
189
+ height: 0.35em;
190
+ z-index: 1;
191
+ background-color: white;
192
+ -webkit-clip-path: polygon(100% 0%, 0 0%, 50% 100%);
193
+ clip-path: polygon(100% 0%, 0 0%, 50% 100%);
194
+ }
195
+
196
+ .select.desktop:not(.select--multiple)::after {
197
+ content: none;
198
+ }
199
+
200
+ .desktop-hide {
201
+ display: none !important;
202
+ }
203
+
204
+ .submitting {
205
+ pointer-events: none;
206
+ touch-action: none;
207
+ }
208
+
209
+ .submitting2 {
210
+ opacity: 0.7;
211
+ }
212
+
213
+ select:focus + .focus {
214
+ position: absolute;
215
+ top: -1px;
216
+ left: -1px;
217
+ right: -1px;
218
+ bottom: -1px;
219
+ border: 0;
220
+ border-radius: inherit;
221
+ }
222
+
223
+ </style>
224
+ <script src="https://code.jquery.com/jquery-3.6.0.slim.min.js"></script>
225
+ </head>
226
+ <body>
227
+ <div id="output">
228
+ <div>
229
+ Web Console | <%= model.name %><br />
230
+ All rights reserved.<br /><br />
231
+ Server boot: <%= model.boot %><br /><br />
232
+ </div>
233
+ <div id="logs">
234
+ <%- model.result %>
235
+
236
+ <% if (model.running && model.readLine) { %>
237
+ <form method="post" style="display: flex; flex: 1" class="commandFormInline">
238
+ <% if (model.readLineOpts.select) { %>
239
+ <div class="select">
240
+ <select id="command" name="command" size="<%= Math.max(2,model.readLineOpts.select.length) %>"
241
+ autofocus="autofocus">
242
+ <option value="[null]" id="empty">Select...</option>
243
+ <% model.readLineOpts.select.forEach(function(x, i) {
244
+ const isArray = Array.isArray(x);
245
+ %>
246
+ <option value="<%= isArray ? x[0] : x %>"><%= isArray ? x[1] : x %></option>
247
+ <% }) %>
248
+ </select>
249
+ <span class="focus"></span>
250
+ </div>
251
+ <% } else { %>
252
+ <input type="<%= model.readLineOpts.secure ? 'password' : 'text' %>" id="command" name="command" style="flex: 1"
253
+ autofocus="autofocus" autocomplete="off" />
254
+ <% } %>
255
+ </form><%- '</div>' %>
256
+ <% } %>
257
+ </div>
258
+ <div id="running"></div>
259
+
260
+ <form method="post" class="commandForm">
261
+ <div id="bottom">
262
+ <% if (!model.running) { %>
263
+ <span id="path">web:/&gt;&nbsp;</span>
264
+ <span id="input"><input type="text" id="command" name="command" autofocus="autofocus" autocomplete="off" /></span>
265
+ <% } %>
266
+ </div>
267
+ </form>
268
+
269
+ <form method="post" id="cancelForm">
270
+ <input type="hidden" name="command" value="ctrl+c" />
271
+ </form>
272
+ <form method="post" id="cancelShiftForm">
273
+ <input type="hidden" name="command" value="ctrl+shift+c" />
274
+ </form>
275
+ </div>
276
+ <div id="bottom-base">
277
+ <% if (model.running) { %>
278
+ <div id="cancel">[ Terminate ]</div>
279
+ <div id="shiftCancel">[ Cancel Signal ]</div>
280
+ <% } else { %>
281
+ <div id="prev">[ Previous ]</div>
282
+ <div id="next">[ Next ]</div>
283
+ <% } %>
284
+ </div>
285
+ <script type="text/javascript">
286
+ document.getElementById('bottom').scrollIntoView(false);
287
+ const commands = JSON.parse(localStorage.getItem('command-history') || '[]');
288
+ const commandStore = {
289
+ index: commands.length,
290
+ commandCount: commands.length,
291
+ prevCommand: commands,
292
+ put: function (val) {
293
+ if (!val)
294
+ return;
295
+ if (this.prevCommand.indexOf(val) > -1) {
296
+ this.prevCommand = this.prevCommand.filter(x => x != val);
297
+ this.commandCount = this.prevCommand.length;
298
+ }
299
+ this.commandCount++;
300
+ this.index = this.commandCount;
301
+ this.prevCommand.push(val);
302
+ if (this.commandCount > 30) {
303
+ this.prevCommand.shift();
304
+ this.commandCount = this.prevCommand.length;
305
+ this.index = this.commandCount;
306
+ }
307
+ localStorage.setItem('command-history', JSON.stringify(this.prevCommand));
308
+ },
309
+ get: function (isUp) {
310
+ if (isUp && this.index > 0)
311
+ this.index--;
312
+ else if (!isUp && this.index < this.commandCount)
313
+ this.index++;
314
+ if (typeof this.prevCommand[this.index] !== "undefined") {
315
+ return this.prevCommand[this.index];
316
+ }
317
+ return '';
318
+ }
319
+
320
+ }
321
+ </script>
322
+ <script type="text/javascript">
323
+ $(document).on('keydown', function (e) {
324
+ e = e || window.event;
325
+ const key = e.which || e.keyCode;
326
+ const ctrl = e.ctrlKey ? e.ctrlKey : ((key === 17) ? true : false);
327
+ const shift = e.shiftKey ? e.shiftKey : ((key === 16) ? true : false);
328
+ const alt = e.altKey ? e.altKey : ((key === 18) ? true : false);
329
+
330
+ <% if (model.running) { %>
331
+
332
+ if (key === 67 && alt && shift) {
333
+ $('#cancelShiftForm').submit();
334
+ } else if (key === 67 && alt) {
335
+ $('#cancelForm').submit();
336
+ }
337
+ <% } else { %>
338
+
339
+ if (key === 38 && $("input").is(":focus")) {
340
+ const val = commandStore.get(true);
341
+ $("input").val(val);
342
+ const input = $("input")[0];
343
+ setTimeout(function () { input.selectionStart = input.selectionEnd = input.value.length; }, 0);
344
+ } else if (key === 40 && $("input").is(":focus")) {
345
+ const val = commandStore.get(false);
346
+ $("input").val(val);
347
+ const input = $("input")[0];
348
+ setTimeout(function () { input.selectionStart = input.selectionEnd = input.value.length; }, 0);
349
+ }
350
+ <% } %>
351
+
352
+ if (key === 13 && $("select").is(":focus")) {
353
+ $('form.commandFormInline').submit();
354
+ }
355
+ });
356
+
357
+ <% if (!model.readLine) { %>
358
+ $("form.commandForm").on("submit", function (e) {
359
+ commandStore.put($('input').val());
360
+ });
361
+ <% } %>
362
+
363
+ <% if (model.running && !model.readLine) { %>
364
+ let start = +'<%= model.result.length %>';
365
+ setInterval(() => {
366
+ fetch('<%= model.url %>/substring/' + start).then(x => x.json())
367
+ .then(x => {
368
+ if (!x.running || x.readLine)
369
+ window.location.href = '<%= model.url %>';
370
+ else if (x.result.length) {
371
+ $('#logs').append(x.result);
372
+ start += x.result.length;
373
+ document.getElementById('bottom').scrollIntoView(false);
374
+ }
375
+ });
376
+ }, 1000);
377
+ let ticks = 1;
378
+ setInterval(() => {
379
+ $('#running').html('.'.repeat(ticks++));
380
+ if (ticks > 3)
381
+ ticks = 1;
382
+ }, 300);
383
+ <% } %>
384
+ if (window.history.replaceState) {
385
+ window.history.replaceState(null, null, window.location.href);
386
+ }
387
+ const isMobile = (navigator.maxTouchPoints || 'ontouchstart' in document.documentElement);
388
+
389
+ <% if (model.readLine && model.readLineOpts.select) { %>
390
+ if (isMobile) {
391
+ $('select').on('change', function () {
392
+ if ($(this).val() !== '[null]')
393
+ $('form.commandFormInline').submit();
394
+ });
395
+ $('select').attr('size', 1);
396
+ } else {
397
+ $('select > option').first().remove();
398
+ $('.select').addClass('desktop');
399
+ }
400
+ $('select')[0].selectedIndex = 0;
401
+ <% } %>
402
+ if (!isMobile) {
403
+ $('#bottom-base').addClass('desktop-hide');
404
+ }
405
+ <% if (model.running) { %>
406
+ if (isMobile) {
407
+ $('#cancel').on('click', function () {
408
+ $('#cancelForm').submit();
409
+ });
410
+ $('#shiftCancel').on('click', function () {
411
+ $('#cancelShiftForm').submit();
412
+ });
413
+ }
414
+ <% } else { %>
415
+
416
+ if (isMobile) {
417
+ $('#prev').on('click', function () {
418
+ const val = commandStore.get(true);
419
+ $("input").val(val);
420
+ const input = $("input")[0];
421
+ setTimeout(function () { input.selectionStart = input.selectionEnd = input.value.length; }, 0);
422
+ });
423
+ $('#next').on('click', function () {
424
+ const val = commandStore.get(false);
425
+ $("input").val(val);
426
+ const input = $("input")[0];
427
+ setTimeout(function () { input.selectionStart = input.selectionEnd = input.value.length; }, 0);
428
+ });
429
+ }
430
+ <% } %>
431
+ $('form').on('submit', function () {
432
+ document.activeElement?.blur();
433
+ $('body').addClass('submitting submitting2');
434
+ });
435
+
436
+ var longpress = false;
437
+
438
+ $("body").on('click', function () {
439
+ if (!longpress)
440
+ document.getElementById('command')?.focus();
441
+ });
442
+
443
+ var startTime, endTime;
444
+ $("body").on('mousedown', function () {
445
+ startTime = new Date().getTime();
446
+ });
447
+
448
+ $("body").on('mouseup', function () {
449
+ endTime = new Date().getTime();
450
+ longpress = (endTime - startTime < 500) ? false : true;
451
+ });
452
+ </script>
453
+ </body>
454
+ </html>
455
+ `
456
+ });
457
+ }
458
+ async getSubstring(req, res, start) {
459
+ const session = this.webConsoleService.getSession(req, res);
460
+ let result;
461
+ if (session.logs.length <= +start)
462
+ result = '';
463
+ else
464
+ result = session.logs.substring(+start);
465
+ return res.send({
466
+ result,
467
+ running: session.running,
468
+ readLine: !!session.readLineCallback,
469
+ });
470
+ }
471
+ async get(req, res) {
472
+ const session = this.webConsoleService.getSession(req, res);
473
+ const globalPrefix = this.appConfig.getGlobalPrefix();
474
+ return res.send(ejs_1.default.render(this.view, {
475
+ model: {
476
+ name: this.consoleOptions.name,
477
+ result: session.logs,
478
+ running: session.running,
479
+ readLine: !!session.readLineCallback,
480
+ readLineOpts: session.readLineOpts,
481
+ boot,
482
+ url: `${globalPrefix || ''}/${endpoint}`
483
+ }
484
+ })
485
+ .replace(/>[\r\n ]+</g, "><")
486
+ .replace(/(<.*?>)|\s+/g, (m, $1) => $1 ? $1 : ' ')
487
+ .trim());
488
+ }
489
+ async post(command, req, res, ip) {
490
+ var _a, _b, _c;
491
+ if (command == null)
492
+ command = '';
493
+ const escaped = command.replace(/\\\|/g, '\r\n');
494
+ const cmds = escaped.split("|").filter(x => x)
495
+ .map(x => x.replace(/\r\n/g, '|'));
496
+ const session = this.webConsoleService.getSession(req, res);
497
+ const globalPrefix = this.appConfig.getGlobalPrefix();
498
+ if (command == 'ctrl+c') {
499
+ session.cancel = true;
500
+ (_a = session.onCancel) === null || _a === void 0 ? void 0 : _a.call(this);
501
+ if (session.readLineCallback) {
502
+ session.readLineCallback(null);
503
+ session.logs += '</div>';
504
+ session.readLineCallback = null;
505
+ }
506
+ session.logs += '<div>Operation canceled</div><br/>';
507
+ session.running = false;
508
+ }
509
+ else if (command == 'ctrl+shift+c') {
510
+ if (session.onCancelSignal)
511
+ (_b = session.onCancelSignal) === null || _b === void 0 ? void 0 : _b.call(this);
512
+ else {
513
+ session.cancel = true;
514
+ (_c = session.onCancel) === null || _c === void 0 ? void 0 : _c.call(this);
515
+ if (session.readLineCallback) {
516
+ session.readLineCallback(null);
517
+ session.logs += '</div>';
518
+ session.readLineCallback = null;
519
+ }
520
+ session.logs += '<div>Operation canceled</div><br/>';
521
+ session.running = false;
522
+ }
523
+ }
524
+ else {
525
+ if (session.readLineCallback) {
526
+ (async () => {
527
+ session.readLineCallback(command);
528
+ })().catch(e => {
529
+ if (session.cancel)
530
+ return;
531
+ session.logs += e + '<br/><br/>';
532
+ session.running = false;
533
+ });
534
+ session.readLineCallback = null;
535
+ }
536
+ else {
537
+ session.cancel = false;
538
+ session.onCancel = null;
539
+ session.running = true;
540
+ (async () => {
541
+ if (!cmds.length) {
542
+ session.logs += `web:/> `;
543
+ }
544
+ for (let i = 0; i < cmds.length; i++) {
545
+ let cmd = cmds[i];
546
+ const { cmd: parsed, arg } = this.webConsoleService.parse(cmd, session);
547
+ await parsed.process({
548
+ session,
549
+ arg,
550
+ req,
551
+ res,
552
+ ip,
553
+ rawCommand: cmd,
554
+ log: (...text) => this.webConsoleService.log(session, this.webConsoleService.escapeHtml(text.map(x => typeof x == "object" ? JSON.stringify(x, null, 2) : x).join(' ')).replace(/\n/g, '<br/>').replace(/\r/g, '').replace(/\s\s/g, ' &nbsp;')),
555
+ logRaw: (text) => this.webConsoleService.log(session, text),
556
+ logTable: (entities, noColumns) => this.webConsoleService.log(session, this.webConsoleService.toTable(entities, noColumns)),
557
+ readArgs: (mapList, parameters) => this.webConsoleService.readArgs(session, arg, mapList, parameters),
558
+ readLine: (title, opts) => this.webConsoleService.readLine(session, title || '', opts),
559
+ parseArgs: (funcArg) => this.webConsoleService.parseArgs(funcArg || arg),
560
+ toTable: this.webConsoleService.toTable,
561
+ loop: this.webConsoleService.loopFactory(session),
562
+ longWork: this.webConsoleService.longWorkFactory(session),
563
+ });
564
+ }
565
+ })().catch(e => {
566
+ if (session.cancel)
567
+ return;
568
+ session.logs += e + '<br/>';
569
+ }).finally(() => {
570
+ if (session.cancel)
571
+ return;
572
+ session.logs += '<br/>';
573
+ session.running = false;
574
+ });
575
+ }
576
+ }
577
+ setImmediate(() => {
578
+ res.send(ejs_1.default.render(this.view, {
579
+ model: {
580
+ name: this.consoleOptions.name,
581
+ result: session.logs,
582
+ running: session.running,
583
+ readLine: !!session.readLineCallback,
584
+ readLineOpts: session.readLineOpts,
585
+ boot,
586
+ url: `${globalPrefix || ''}/${endpoint}`
587
+ }
588
+ })
589
+ .replace(/>[\r\n ]+</g, "><")
590
+ .replace(/(<.*?>)|\s+/g, (m, $1) => $1 ? $1 : ' ')
591
+ .trim());
592
+ });
593
+ }
594
+ invite(input) {
595
+ return this.remoteConsoleService.inviteThisConsole(input.name, input.v, input.p);
596
+ }
597
+ stream(input) {
598
+ return this.remoteConsoleService.pumpStream(input);
599
+ }
600
+ close(input) {
601
+ return this.remoteConsoleService.closeFromRemote(input.name);
602
+ }
603
+ downloadTemp(name, res) {
604
+ const file = this.tempFileService.read(name);
605
+ switch (file.type) {
606
+ case 'csv':
607
+ if (!res['csv'])
608
+ throw new common_1.BadRequestException('Module csv-express not installed');
609
+ res.charset = 'utf8';
610
+ return res['csv'](file.content, true);
611
+ case 'html':
612
+ res.setHeader('Content-Type', 'text/html');
613
+ return res.send(file.content);
614
+ }
615
+ throw new common_1.BadRequestException(`Invalid file type: ${file.type}`);
616
+ }
617
+ };
618
+ __decorate([
619
+ (0, common_1.Inject)('CONFIG_ROOT_OPTIONS'),
620
+ __metadata("design:type", Object)
621
+ ], WebConsoleController.prototype, "consoleOptions", void 0);
622
+ __decorate([
623
+ (0, common_1.Inject)(core_1.ApplicationConfig),
624
+ __metadata("design:type", core_1.ApplicationConfig)
625
+ ], WebConsoleController.prototype, "appConfig", void 0);
626
+ __decorate([
627
+ (0, common_1.Get)('substring/:start'),
628
+ __param(0, (0, common_1.Req)()),
629
+ __param(1, (0, common_1.Res)()),
630
+ __param(2, (0, common_1.Param)('start')),
631
+ __metadata("design:type", Function),
632
+ __metadata("design:paramtypes", [Object, Object, String]),
633
+ __metadata("design:returntype", Promise)
634
+ ], WebConsoleController.prototype, "getSubstring", null);
635
+ __decorate([
636
+ (0, common_1.Get)(),
637
+ __param(0, (0, common_1.Req)()),
638
+ __param(1, (0, common_1.Res)()),
639
+ __metadata("design:type", Function),
640
+ __metadata("design:paramtypes", [Object, Object]),
641
+ __metadata("design:returntype", Promise)
642
+ ], WebConsoleController.prototype, "get", null);
643
+ __decorate([
644
+ (0, common_1.Post)(),
645
+ __param(0, (0, common_1.Body)('command')),
646
+ __param(1, (0, common_1.Req)()),
647
+ __param(2, (0, common_1.Res)()),
648
+ __param(3, (0, common_1.Ip)()),
649
+ __metadata("design:type", Function),
650
+ __metadata("design:paramtypes", [String, Object, Object, String]),
651
+ __metadata("design:returntype", Promise)
652
+ ], WebConsoleController.prototype, "post", null);
653
+ __decorate([
654
+ (0, common_1.Get)('remote/invite'),
655
+ __param(0, (0, common_1.Query)()),
656
+ __metadata("design:type", Function),
657
+ __metadata("design:paramtypes", [Object]),
658
+ __metadata("design:returntype", void 0)
659
+ ], WebConsoleController.prototype, "invite", null);
660
+ __decorate([
661
+ (0, common_1.Post)('remote/stream'),
662
+ __param(0, (0, common_1.Body)()),
663
+ __metadata("design:type", Function),
664
+ __metadata("design:paramtypes", [Object]),
665
+ __metadata("design:returntype", void 0)
666
+ ], WebConsoleController.prototype, "stream", null);
667
+ __decorate([
668
+ (0, common_1.Post)('remote/close'),
669
+ __param(0, (0, common_1.Body)()),
670
+ __metadata("design:type", Function),
671
+ __metadata("design:paramtypes", [Object]),
672
+ __metadata("design:returntype", void 0)
673
+ ], WebConsoleController.prototype, "close", null);
674
+ __decorate([
675
+ (0, common_1.Get)('file/:name'),
676
+ __param(0, (0, common_1.Param)('name')),
677
+ __param(1, (0, common_1.Res)()),
678
+ __metadata("design:type", Function),
679
+ __metadata("design:paramtypes", [String, Object]),
680
+ __metadata("design:returntype", void 0)
681
+ ], WebConsoleController.prototype, "downloadTemp", null);
682
+ WebConsoleController = __decorate([
683
+ (0, common_1.Controller)(endpoint || 'console'),
684
+ (0, common_1.UseFilters)(http_exception_filter_1.HttpExceptionFilter),
685
+ __metadata("design:paramtypes", [web_console_service_1.WebConsoleService, remote_console_service_1.RemoteConsoleService,
686
+ temp_file_service_1.TempFileService])
687
+ ], WebConsoleController);
688
+ return WebConsoleController;
689
+ }
690
+ exports.WebConsoleControllerFactory = WebConsoleControllerFactory;