nestjs-web-console 0.2.22 → 1.0.1

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