nestjs-web-console 1.0.2 → 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,4 +1,4 @@
1
- import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
2
- export declare class HttpExceptionFilter implements ExceptionFilter {
3
- catch(exception: Error, host: ArgumentsHost): void;
4
- }
1
+ import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
2
+ export declare class HttpExceptionFilter implements ExceptionFilter {
3
+ catch(exception: Error, host: ArgumentsHost): void;
4
+ }
@@ -1,50 +1,50 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.HttpExceptionFilter = void 0;
10
- const common_1 = require("@nestjs/common");
11
- let HttpExceptionFilter = class HttpExceptionFilter {
12
- catch(exception, host) {
13
- const ctx = host.switchToHttp();
14
- const response = ctx.getResponse();
15
- if (exception instanceof common_1.HttpException) {
16
- const status = exception.getStatus();
17
- if (status == 404)
18
- response.status(status).send({
19
- message: 'Not Found',
20
- code: 'not_found',
21
- });
22
- else if (status == 500) {
23
- response.status(status).send({
24
- message: 'An unhandled error occured. ' + exception.getResponse(),
25
- code: 'generic_error',
26
- });
27
- console.log('Generic error: ', exception.getResponse());
28
- }
29
- else {
30
- response.status(status).send(exception.getResponse() && exception.getResponse().statusCode
31
- ? {
32
- message: exception.getResponse().message || 'An exception occured',
33
- code: exception.getResponse().message,
34
- }
35
- : exception.getResponse());
36
- }
37
- }
38
- else {
39
- response.status(500).send({
40
- message: 'An unhandled error occured',
41
- code: 'generic_error',
42
- });
43
- console.error('Generic error: ', exception.stack || exception.message);
44
- }
45
- }
46
- };
47
- HttpExceptionFilter = __decorate([
48
- (0, common_1.Catch)(Error)
49
- ], HttpExceptionFilter);
50
- exports.HttpExceptionFilter = HttpExceptionFilter;
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.HttpExceptionFilter = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ let HttpExceptionFilter = class HttpExceptionFilter {
12
+ catch(exception, host) {
13
+ const ctx = host.switchToHttp();
14
+ const response = ctx.getResponse();
15
+ if (exception instanceof common_1.HttpException) {
16
+ const status = exception.getStatus();
17
+ if (status == 404)
18
+ response.status(status).send({
19
+ message: 'Not Found',
20
+ code: 'not_found',
21
+ });
22
+ else if (status == 500) {
23
+ response.status(status).send({
24
+ message: 'An unhandled error occured. ' + exception.getResponse(),
25
+ code: 'generic_error',
26
+ });
27
+ console.log('Generic error: ', exception.getResponse());
28
+ }
29
+ else {
30
+ response.status(status).send(exception.getResponse() && exception.getResponse().statusCode
31
+ ? {
32
+ message: exception.getResponse().message || 'An exception occured',
33
+ code: exception.getResponse().message,
34
+ }
35
+ : exception.getResponse());
36
+ }
37
+ }
38
+ else {
39
+ response.status(500).send({
40
+ message: 'An unhandled error occured',
41
+ code: 'generic_error',
42
+ });
43
+ console.error('Generic error: ', exception.stack || exception.message);
44
+ }
45
+ }
46
+ };
47
+ HttpExceptionFilter = __decorate([
48
+ (0, common_1.Catch)(Error)
49
+ ], HttpExceptionFilter);
50
+ exports.HttpExceptionFilter = HttpExceptionFilter;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export * from './console.types';
2
- export * from './web.console.module';
3
- export * from './services/web.console.service';
4
- export * from './services/temp.file.service';
5
- export * from './services/processors';
6
- export * from './services/processors/base/console.command';
7
- export * from './services/processors/base/invalid.command';
8
- export * from './services/processors/base/not-logged.command';
1
+ export * from './console.types';
2
+ export * from './web.console.module';
3
+ export * from './services/web.console.service';
4
+ export * from './services/temp.file.service';
5
+ export * from './services/processors';
6
+ export * from './services/processors/base/console.command';
7
+ export * from './services/processors/base/invalid.command';
8
+ export * from './services/processors/base/not-logged.command';
package/dist/index.js CHANGED
@@ -1,24 +1,24 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = 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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./console.types"), exports);
18
- __exportStar(require("./web.console.module"), exports);
19
- __exportStar(require("./services/web.console.service"), exports);
20
- __exportStar(require("./services/temp.file.service"), exports);
21
- __exportStar(require("./services/processors"), exports);
22
- __exportStar(require("./services/processors/base/console.command"), exports);
23
- __exportStar(require("./services/processors/base/invalid.command"), exports);
24
- __exportStar(require("./services/processors/base/not-logged.command"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = 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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./console.types"), exports);
18
+ __exportStar(require("./web.console.module"), exports);
19
+ __exportStar(require("./services/web.console.service"), exports);
20
+ __exportStar(require("./services/temp.file.service"), exports);
21
+ __exportStar(require("./services/processors"), exports);
22
+ __exportStar(require("./services/processors/base/console.command"), exports);
23
+ __exportStar(require("./services/processors/base/invalid.command"), exports);
24
+ __exportStar(require("./services/processors/base/not-logged.command"), exports);
@@ -1,3 +1,3 @@
1
- import { Type } from "@nestjs/common";
2
- import { ConsoleCommand } from "./processors/base/console.command";
3
- export declare const ALL_COMMANDS: Type<ConsoleCommand>[];
1
+ import { Type } from "@nestjs/common";
2
+ import { ConsoleCommand } from "./processors/base/console.command";
3
+ export declare const ALL_COMMANDS: Type<ConsoleCommand>[];
@@ -1,13 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ALL_COMMANDS = void 0;
4
- const processors_1 = require("./processors");
5
- exports.ALL_COMMANDS = [
6
- processors_1.HelpCommand,
7
- processors_1.LoginCommand,
8
- processors_1.LogoutCommand,
9
- processors_1.ClearScreenCommand,
10
- processors_1.BashCommand,
11
- processors_1.CmdCommand,
12
- processors_1.JoinCommand,
13
- ];
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ALL_COMMANDS = void 0;
4
+ const processors_1 = require("./processors");
5
+ exports.ALL_COMMANDS = [
6
+ processors_1.HelpCommand,
7
+ processors_1.LoginCommand,
8
+ processors_1.LogoutCommand,
9
+ processors_1.ClearScreenCommand,
10
+ processors_1.BashCommand,
11
+ processors_1.CmdCommand,
12
+ processors_1.JoinCommand,
13
+ ];
@@ -1,8 +1,8 @@
1
- import { CommandProcessParameters } from "../../web.console.service";
2
- export declare abstract class ConsoleCommand {
3
- command: string;
4
- description: string;
5
- requiresAuth: boolean;
6
- constructor();
7
- abstract process(parameters: CommandProcessParameters): any;
8
- }
1
+ import { CommandProcessParameters } from "../../web.console.service";
2
+ export declare abstract class ConsoleCommand {
3
+ command: string;
4
+ description: string;
5
+ requiresAuth: boolean;
6
+ constructor();
7
+ abstract process(parameters: CommandProcessParameters): any;
8
+ }
@@ -1,27 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConsoleCommand = void 0;
4
- class ConsoleCommand {
5
- constructor() {
6
- Object.defineProperty(this, "command", {
7
- enumerable: true,
8
- configurable: true,
9
- writable: true,
10
- value: void 0
11
- });
12
- Object.defineProperty(this, "description", {
13
- enumerable: true,
14
- configurable: true,
15
- writable: true,
16
- value: void 0
17
- });
18
- Object.defineProperty(this, "requiresAuth", {
19
- enumerable: true,
20
- configurable: true,
21
- writable: true,
22
- value: void 0
23
- });
24
- this.requiresAuth = true;
25
- }
26
- }
27
- exports.ConsoleCommand = ConsoleCommand;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConsoleCommand = void 0;
4
+ class ConsoleCommand {
5
+ constructor() {
6
+ Object.defineProperty(this, "command", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: void 0
11
+ });
12
+ Object.defineProperty(this, "description", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ Object.defineProperty(this, "requiresAuth", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ this.requiresAuth = true;
25
+ }
26
+ }
27
+ exports.ConsoleCommand = ConsoleCommand;
@@ -1,5 +1,5 @@
1
- import { CommandProcessParameters } from "../../web.console.service";
2
- import { ConsoleCommand } from "./console.command";
3
- export declare class InvalidCommand extends ConsoleCommand {
4
- process({ log, arg }: CommandProcessParameters): void;
5
- }
1
+ import { CommandProcessParameters } from "../../web.console.service";
2
+ import { ConsoleCommand } from "./console.command";
3
+ export declare class InvalidCommand extends ConsoleCommand {
4
+ process({ log, arg }: CommandProcessParameters): void;
5
+ }
@@ -1,14 +1,14 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.InvalidCommand = void 0;
7
- const lodash_1 = __importDefault(require("lodash"));
8
- const console_command_1 = require("./console.command");
9
- class InvalidCommand extends console_command_1.ConsoleCommand {
10
- process({ log, arg }) {
11
- log(`No command found with name "${lodash_1.default.escape(arg)}". Type "help" to list all possible commands.`);
12
- }
13
- }
14
- exports.InvalidCommand = InvalidCommand;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.InvalidCommand = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const console_command_1 = require("./console.command");
9
+ class InvalidCommand extends console_command_1.ConsoleCommand {
10
+ process({ log, arg }) {
11
+ log(`No command found with name "${lodash_1.default.escape(arg)}". Type "help" to list all possible commands.`);
12
+ }
13
+ }
14
+ exports.InvalidCommand = InvalidCommand;
@@ -1,5 +1,5 @@
1
- import { CommandProcessParameters } from "../../web.console.service";
2
- import { ConsoleCommand } from "./console.command";
3
- export declare class NotLoggedCommand extends ConsoleCommand {
4
- process({ log }: CommandProcessParameters): void;
5
- }
1
+ import { CommandProcessParameters } from "../../web.console.service";
2
+ import { ConsoleCommand } from "./console.command";
3
+ export declare class NotLoggedCommand extends ConsoleCommand {
4
+ process({ log }: CommandProcessParameters): void;
5
+ }
@@ -1,10 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotLoggedCommand = void 0;
4
- const console_command_1 = require("./console.command");
5
- class NotLoggedCommand extends console_command_1.ConsoleCommand {
6
- process({ log }) {
7
- log(`You must be logged in to execute this command.`);
8
- }
9
- }
10
- exports.NotLoggedCommand = NotLoggedCommand;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotLoggedCommand = void 0;
4
+ const console_command_1 = require("./console.command");
5
+ class NotLoggedCommand extends console_command_1.ConsoleCommand {
6
+ process({ log }) {
7
+ log(`You must be logged in to execute this command.`);
8
+ }
9
+ }
10
+ exports.NotLoggedCommand = NotLoggedCommand;
@@ -1,7 +1,7 @@
1
- import { CommandProcessParameters } from "../web.console.service";
2
- import { ConsoleCommand } from "./base/console.command";
3
- export declare class BashCommand extends ConsoleCommand {
4
- constructor();
5
- getInput(input: any): string;
6
- process({ logRaw, arg, session, parseArgs, readLine }: CommandProcessParameters): Promise<void>;
7
- }
1
+ import { CommandProcessParameters } from "../web.console.service";
2
+ import { ConsoleCommand } from "./base/console.command";
3
+ export declare class BashCommand extends ConsoleCommand {
4
+ constructor();
5
+ getInput(input: any): string;
6
+ process({ logRaw, arg, session, parseArgs, readLine }: CommandProcessParameters): Promise<void>;
7
+ }
@@ -1,102 +1,102 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.BashCommand = void 0;
16
- const common_1 = require("@nestjs/common");
17
- const child_process_1 = require("child_process");
18
- const lodash_1 = __importDefault(require("lodash"));
19
- const console_command_1 = require("./base/console.command");
20
- let BashCommand = class BashCommand extends console_command_1.ConsoleCommand {
21
- constructor() {
22
- super();
23
- this.command = 'bash';
24
- this.description = 'Creates a bash process';
25
- }
26
- getInput(input) {
27
- const postCommand = 'echo " " && echo $(pwd) $\n';
28
- return input ? (input + ' && ' + postCommand) : postCommand;
29
- }
30
- async process({ logRaw, arg, session, parseArgs, readLine }) {
31
- await new Promise((res, rej) => {
32
- const process = (0, child_process_1.spawn)('sh', parseArgs());
33
- session.onCancelSignal = () => {
34
- process.kill("SIGINT");
35
- };
36
- session.onCancel = () => {
37
- process.kill();
38
- };
39
- const handleOutput = chunk => {
40
- let out = new Buffer(chunk, 'utf-8').toString();
41
- const waitingInput = out.charCodeAt(out.length - 2) == 36;
42
- if (waitingInput) {
43
- if (out.endsWith('\n'))
44
- out = out.slice(0, -1);
45
- out = escapeHtml(out).replace(/\n/g, '<br/>').replace(/\r/g, '').replace(/\s\s/g, ' &nbsp;');
46
- const [, ...captures] = out.match(/(.*<br\/>)?(.*)/m);
47
- lodash_1.default.dropRight(captures, 1).forEach(capture => capture && logRaw(capture));
48
- readLine(lodash_1.default.last(captures) || '').then(input => {
49
- process.stdin.write(this.getInput(input));
50
- });
51
- }
52
- else {
53
- out = escapeHtml(out).replace(/\n/g, '<br/>').replace(/\r/g, '').replace(/\s\s/g, ' &nbsp;');
54
- out && logRaw(out);
55
- }
56
- };
57
- const handleError = chunk => {
58
- let out = new Buffer(chunk, 'utf-8').toString();
59
- if (out.endsWith('\n'))
60
- out = out.slice(0, -1);
61
- out = escapeHtml(out).replace(/\n/g, '<br/>').replace(/\r/g, '').replace(/\s\s/g, ' &nbsp;');
62
- out && logRaw(out);
63
- logRaw('&nbsp;');
64
- if (!process.killed)
65
- process.stdin.write(this.getInput(null));
66
- };
67
- process.stdout.on('data', handleOutput);
68
- process.stderr.on('data', handleError);
69
- process.on('error', e => {
70
- rej(e);
71
- });
72
- function exitHandler(options, exitCode) {
73
- if (options.cleanup)
74
- console.log('clean');
75
- if (exitCode || exitCode === 0)
76
- console.log(exitCode);
77
- res(null);
78
- }
79
- process.on('exit', exitHandler.bind(null, { cleanup: true }));
80
- process.on('SIGINT', exitHandler.bind(null, { exit: true }));
81
- process.on('SIGUSR1', exitHandler.bind(null, { exit: true }));
82
- process.on('SIGUSR2', exitHandler.bind(null, { exit: true }));
83
- process.on('uncaughtException', exitHandler.bind(null, { exit: true }));
84
- if (!arg) {
85
- process.stdin.write(this.getInput(null));
86
- }
87
- });
88
- }
89
- };
90
- BashCommand = __decorate([
91
- (0, common_1.Injectable)(),
92
- __metadata("design:paramtypes", [])
93
- ], BashCommand);
94
- exports.BashCommand = BashCommand;
95
- function escapeHtml(unsafe) {
96
- return unsafe
97
- .replace(/&/g, "&amp;")
98
- .replace(/</g, "&lt;")
99
- .replace(/>/g, "&gt;")
100
- .replace(/"/g, "&quot;")
101
- .replace(/'/g, "&#039;");
102
- }
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BashCommand = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const child_process_1 = require("child_process");
18
+ const lodash_1 = __importDefault(require("lodash"));
19
+ const console_command_1 = require("./base/console.command");
20
+ let BashCommand = class BashCommand extends console_command_1.ConsoleCommand {
21
+ constructor() {
22
+ super();
23
+ this.command = 'bash';
24
+ this.description = 'Creates a bash process';
25
+ }
26
+ getInput(input) {
27
+ const postCommand = 'echo " " && echo $(pwd) $\n';
28
+ return input ? (input + ' && ' + postCommand) : postCommand;
29
+ }
30
+ async process({ logRaw, arg, session, parseArgs, readLine }) {
31
+ await new Promise((res, rej) => {
32
+ const process = (0, child_process_1.spawn)('sh', parseArgs());
33
+ session.onCancelSignal = () => {
34
+ process.kill("SIGINT");
35
+ };
36
+ session.onCancel = () => {
37
+ process.kill();
38
+ };
39
+ const handleOutput = chunk => {
40
+ let out = new Buffer(chunk, 'utf-8').toString();
41
+ const waitingInput = out.charCodeAt(out.length - 2) == 36;
42
+ if (waitingInput) {
43
+ if (out.endsWith('\n'))
44
+ out = out.slice(0, -1);
45
+ out = escapeHtml(out).replace(/\n/g, '<br/>').replace(/\r/g, '').replace(/\s\s/g, ' &nbsp;');
46
+ const [, ...captures] = out.match(/(.*<br\/>)?(.*)/m);
47
+ lodash_1.default.dropRight(captures, 1).forEach(capture => capture && logRaw(capture));
48
+ readLine(lodash_1.default.last(captures) || '').then(input => {
49
+ process.stdin.write(this.getInput(input));
50
+ });
51
+ }
52
+ else {
53
+ out = escapeHtml(out).replace(/\n/g, '<br/>').replace(/\r/g, '').replace(/\s\s/g, ' &nbsp;');
54
+ out && logRaw(out);
55
+ }
56
+ };
57
+ const handleError = chunk => {
58
+ let out = new Buffer(chunk, 'utf-8').toString();
59
+ if (out.endsWith('\n'))
60
+ out = out.slice(0, -1);
61
+ out = escapeHtml(out).replace(/\n/g, '<br/>').replace(/\r/g, '').replace(/\s\s/g, ' &nbsp;');
62
+ out && logRaw(out);
63
+ logRaw('&nbsp;');
64
+ if (!process.killed)
65
+ process.stdin.write(this.getInput(null));
66
+ };
67
+ process.stdout.on('data', handleOutput);
68
+ process.stderr.on('data', handleError);
69
+ process.on('error', e => {
70
+ rej(e);
71
+ });
72
+ function exitHandler(options, exitCode) {
73
+ if (options.cleanup)
74
+ console.log('clean');
75
+ if (exitCode || exitCode === 0)
76
+ console.log(exitCode);
77
+ res(null);
78
+ }
79
+ process.on('exit', exitHandler.bind(null, { cleanup: true }));
80
+ process.on('SIGINT', exitHandler.bind(null, { exit: true }));
81
+ process.on('SIGUSR1', exitHandler.bind(null, { exit: true }));
82
+ process.on('SIGUSR2', exitHandler.bind(null, { exit: true }));
83
+ process.on('uncaughtException', exitHandler.bind(null, { exit: true }));
84
+ if (!arg) {
85
+ process.stdin.write(this.getInput(null));
86
+ }
87
+ });
88
+ }
89
+ };
90
+ BashCommand = __decorate([
91
+ (0, common_1.Injectable)(),
92
+ __metadata("design:paramtypes", [])
93
+ ], BashCommand);
94
+ exports.BashCommand = BashCommand;
95
+ function escapeHtml(unsafe) {
96
+ return unsafe
97
+ .replace(/&/g, "&amp;")
98
+ .replace(/</g, "&lt;")
99
+ .replace(/>/g, "&gt;")
100
+ .replace(/"/g, "&quot;")
101
+ .replace(/'/g, "&#039;");
102
+ }
@@ -1,6 +1,6 @@
1
- import { CommandProcessParameters } from "../web.console.service";
2
- import { ConsoleCommand } from "./base/console.command";
3
- export declare class ClearScreenCommand extends ConsoleCommand {
4
- constructor();
5
- process({ session }: CommandProcessParameters): Promise<void>;
6
- }
1
+ import { CommandProcessParameters } from "../web.console.service";
2
+ import { ConsoleCommand } from "./base/console.command";
3
+ export declare class ClearScreenCommand extends ConsoleCommand {
4
+ constructor();
5
+ process({ session }: CommandProcessParameters): Promise<void>;
6
+ }