verteilen-core 1.2.4 → 1.2.7

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 (142) hide show
  1. package/dist/client/analysis.d.ts +35 -0
  2. package/dist/client/analysis.js +382 -0
  3. package/dist/client/client.d.ts +25 -0
  4. package/dist/client/client.js +227 -0
  5. package/dist/client/cluster.d.ts +1 -0
  6. package/dist/{src/client → client}/cluster.js +1 -2
  7. package/dist/client/database.d.ts +13 -0
  8. package/dist/client/database.js +37 -0
  9. package/dist/client/execute.d.ts +24 -0
  10. package/dist/{src/client → client}/execute.js +61 -51
  11. package/dist/client/http.d.ts +7 -0
  12. package/dist/client/http.js +40 -0
  13. package/dist/client/javascript.d.ts +47 -0
  14. package/dist/{src/client → client}/javascript.js +110 -136
  15. package/dist/client/job_database.d.ts +10 -0
  16. package/dist/client/job_database.js +34 -0
  17. package/dist/client/job_execute.d.ts +20 -0
  18. package/dist/client/job_execute.js +173 -0
  19. package/dist/client/os.d.ts +29 -0
  20. package/dist/client/os.js +197 -0
  21. package/dist/client/resource.d.ts +7 -0
  22. package/dist/client/resource.js +107 -0
  23. package/dist/client/shell.d.ts +16 -0
  24. package/dist/client/shell.js +122 -0
  25. package/dist/computed.d.ts +13 -0
  26. package/dist/index.d.ts +3 -0
  27. package/dist/index.js +3 -3
  28. package/dist/interface/base.d.ts +70 -0
  29. package/dist/interface/bus.d.ts +90 -0
  30. package/dist/interface/enum.d.ts +143 -0
  31. package/dist/interface/execute.d.ts +20 -0
  32. package/dist/interface/record.d.ts +93 -0
  33. package/dist/interface/server.d.ts +76 -0
  34. package/dist/interface/struct.d.ts +182 -0
  35. package/dist/interface/table.d.ts +20 -0
  36. package/dist/interface/ui.d.ts +29 -0
  37. package/dist/interface.d.ts +29 -0
  38. package/dist/plugins/i18n.d.ts +1666 -0
  39. package/dist/script/console_manager.d.ts +18 -0
  40. package/dist/script/console_manager.js +131 -0
  41. package/dist/script/console_server_manager.d.ts +13 -0
  42. package/dist/script/console_server_manager.js +40 -0
  43. package/dist/script/execute/base.d.ts +45 -0
  44. package/dist/script/execute/base.js +200 -0
  45. package/dist/script/execute/feedback.d.ts +12 -0
  46. package/dist/script/execute/feedback.js +179 -0
  47. package/dist/script/execute/interface.d.ts +8 -0
  48. package/dist/script/execute/region_job.d.ts +5 -0
  49. package/dist/{src/script → script}/execute/region_job.js +1 -0
  50. package/dist/script/execute/region_project.d.ts +10 -0
  51. package/dist/{src/script → script}/execute/region_project.js +4 -0
  52. package/dist/script/execute/region_subtask.d.ts +5 -0
  53. package/dist/{src/script → script}/execute/region_subtask.js +1 -0
  54. package/dist/script/execute/region_task.d.ts +10 -0
  55. package/dist/{src/script → script}/execute/region_task.js +4 -0
  56. package/dist/script/execute/runner.d.ts +14 -0
  57. package/dist/script/execute/runner.js +264 -0
  58. package/dist/script/execute/util_parser.d.ts +14 -0
  59. package/dist/script/execute/util_parser.js +135 -0
  60. package/dist/script/execute_manager.d.ts +25 -0
  61. package/dist/script/execute_manager.js +297 -0
  62. package/dist/script/socket_manager.d.ts +31 -0
  63. package/dist/script/socket_manager.js +263 -0
  64. package/dist/script/webhook_manager.d.ts +3 -0
  65. package/dist/script/webhook_server_manager.d.ts +13 -0
  66. package/dist/script/webhook_server_manager.js +133 -0
  67. package/dist/server/detail.d.ts +72 -0
  68. package/dist/server/detail.js +451 -0
  69. package/dist/server/io.d.ts +46 -0
  70. package/dist/{src/server → server}/io.js +42 -51
  71. package/dist/server/plugin.d.ts +18 -0
  72. package/dist/{src/server → server}/plugin.js +45 -54
  73. package/dist/server/server.d.ts +27 -0
  74. package/dist/server/server.js +53 -0
  75. package/dist/server.d.ts +4 -0
  76. package/dist/util/console_handle.d.ts +20 -0
  77. package/dist/util/console_handle.js +244 -0
  78. package/dist/util/log_handle.d.ts +23 -0
  79. package/dist/util/log_handle.js +224 -0
  80. package/index.ts +1 -6
  81. package/package.json +1 -1
  82. package/src/index.ts +6 -0
  83. package/test/TEST.d.ts +1 -0
  84. package/test/TEST.js +88 -0
  85. package/test/client/execute.test.d.ts +1 -0
  86. package/{dist/test → test}/client/execute.test.js +6 -15
  87. package/test/client/javascript.test.d.ts +1 -0
  88. package/{dist/test → test}/client/javascript.test.js +21 -30
  89. package/test/client/server.test.d.ts +1 -0
  90. package/test/client/task.test.d.ts +1 -0
  91. package/{dist/test → test}/client/task.test.js +1 -1
  92. package/test/script/parser.test.d.ts +1 -0
  93. package/test/script/socket.test.d.ts +1 -0
  94. package/tsconfig.json +8 -4
  95. package/dist/jest.config.js +0 -8
  96. package/dist/src/client/analysis.js +0 -383
  97. package/dist/src/client/client.js +0 -233
  98. package/dist/src/client/database.js +0 -36
  99. package/dist/src/client/http.js +0 -37
  100. package/dist/src/client/job_database.js +0 -36
  101. package/dist/src/client/job_execute.js +0 -171
  102. package/dist/src/client/job_parameter.js +0 -36
  103. package/dist/src/client/os.js +0 -202
  104. package/dist/src/client/parameter.js +0 -36
  105. package/dist/src/client/resource.js +0 -118
  106. package/dist/src/client/shell.js +0 -118
  107. package/dist/src/script/console_manager.js +0 -125
  108. package/dist/src/script/console_server_manager.js +0 -37
  109. package/dist/src/script/execute/base.js +0 -197
  110. package/dist/src/script/execute/feedback.js +0 -188
  111. package/dist/src/script/execute/runner.js +0 -274
  112. package/dist/src/script/execute/util_parser.js +0 -137
  113. package/dist/src/script/execute_manager.js +0 -309
  114. package/dist/src/script/socket_manager.js +0 -260
  115. package/dist/src/script/webhook_server_manager.js +0 -140
  116. package/dist/src/server/detail.js +0 -428
  117. package/dist/src/server/server.js +0 -51
  118. package/dist/src/util/console_handle.js +0 -248
  119. package/dist/src/util/log_handle.js +0 -230
  120. package/dist/src/util/server/console_handle.js +0 -248
  121. package/dist/src/util/server/log_handle.js +0 -230
  122. package/dist/test/TEST.js +0 -105
  123. /package/dist/{src/computed.js → computed.js} +0 -0
  124. /package/dist/{src/interface → interface}/base.js +0 -0
  125. /package/dist/{src/interface → interface}/bus.js +0 -0
  126. /package/dist/{src/interface → interface}/enum.js +0 -0
  127. /package/dist/{src/interface → interface}/execute.js +0 -0
  128. /package/dist/{src/interface → interface}/record.js +0 -0
  129. /package/dist/{src/interface → interface}/server.js +0 -0
  130. /package/dist/{src/interface → interface}/struct.js +0 -0
  131. /package/dist/{src/interface → interface}/table.js +0 -0
  132. /package/dist/{src/interface → interface}/ui.js +0 -0
  133. /package/dist/{src/interface.js → interface.js} +0 -0
  134. /package/dist/{src/lan → lan}/en.json +0 -0
  135. /package/dist/{src/lan → lan}/zh_TW.json +0 -0
  136. /package/dist/{src/plugins → plugins}/i18n.js +0 -0
  137. /package/dist/{src/script → script}/execute/interface.js +0 -0
  138. /package/dist/{src/script → script}/webhook_manager.js +0 -0
  139. /package/dist/{src/server.js → server.js} +0 -0
  140. /package/{dist/test → test}/client/server.test.js +0 -0
  141. /package/{dist/test → test}/script/parser.test.js +0 -0
  142. /package/{dist/test → test}/script/socket.test.js +0 -0
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const job_database_1 = require("../../src/client/job_database");
13
4
  const javascript_1 = require("../../src/client/javascript");
@@ -44,17 +35,17 @@ describe("JS Test", () => {
44
35
  database = undefined;
45
36
  lib = undefined;
46
37
  });
47
- test("Env test getter", () => __awaiter(void 0, void 0, void 0, function* () {
48
- expect(yield js.JavascriptExecuteWithLib(`return env.getnumber("n1");`, [])).toBe(7);
49
- expect(yield js.JavascriptExecuteWithLib(`return env.getnumber("n2");`, [])).toBe(5);
50
- expect(yield js.JavascriptExecuteWithLib(`return env.getstring("s1");`, [])).toBe("Hello World");
51
- expect(yield js.JavascriptExecuteWithLib(`return env.getboolean("b1");`, [])).toBe(true);
52
- expect(yield js.JavascriptExecuteWithLib(`return env.getnumber("nnn");`, [])).toBe(undefined);
53
- expect(yield js.JavascriptExecuteWithLib(`return env.getstring("sss");`, [])).toBe(undefined);
54
- expect(yield js.JavascriptExecuteWithLib(`return env.getboolean("bbb");`, [])).toBe(undefined);
55
- }));
56
- test("Env test loop", () => __awaiter(void 0, void 0, void 0, function* () {
57
- expect(yield js.JavascriptExecuteWithLib(`
38
+ test("Env test getter", async () => {
39
+ expect(await js.JavascriptExecuteWithLib(`return env.getnumber("n1");`, [])).toBe(7);
40
+ expect(await js.JavascriptExecuteWithLib(`return env.getnumber("n2");`, [])).toBe(5);
41
+ expect(await js.JavascriptExecuteWithLib(`return env.getstring("s1");`, [])).toBe("Hello World");
42
+ expect(await js.JavascriptExecuteWithLib(`return env.getboolean("b1");`, [])).toBe(true);
43
+ expect(await js.JavascriptExecuteWithLib(`return env.getnumber("nnn");`, [])).toBe(undefined);
44
+ expect(await js.JavascriptExecuteWithLib(`return env.getstring("sss");`, [])).toBe(undefined);
45
+ expect(await js.JavascriptExecuteWithLib(`return env.getboolean("bbb");`, [])).toBe(undefined);
46
+ });
47
+ test("Env test loop", async () => {
48
+ expect(await js.JavascriptExecuteWithLib(`
58
49
  result = 0;
59
50
  n = env.getnumber("n2");
60
51
  for(i=0;i<3;i++){
@@ -62,14 +53,14 @@ describe("JS Test", () => {
62
53
  }
63
54
  return result;
64
55
  `, [])).toBe(15);
65
- }));
66
- test("Env test has", () => __awaiter(void 0, void 0, void 0, function* () {
67
- expect(yield js.JavascriptExecuteWithLib(`return env.hasnumber("n1");`, [])).toBe(true);
68
- expect(yield js.JavascriptExecuteWithLib(`return env.hasnumber("n2");`, [])).toBe(true);
69
- expect(yield js.JavascriptExecuteWithLib(`return env.hasstring("s1");`, [])).toBe(true);
70
- expect(yield js.JavascriptExecuteWithLib(`return env.hasboolean("b1");`, [])).toBe(true);
71
- expect(yield js.JavascriptExecuteWithLib(`return env.hasnumber("nnn");`, [])).toBe(false);
72
- expect(yield js.JavascriptExecuteWithLib(`return env.hasstring("sss");`, [])).toBe(false);
73
- expect(yield js.JavascriptExecuteWithLib(`return env.hasboolean("bbb");`, [])).toBe(false);
74
- }));
56
+ });
57
+ test("Env test has", async () => {
58
+ expect(await js.JavascriptExecuteWithLib(`return env.hasnumber("n1");`, [])).toBe(true);
59
+ expect(await js.JavascriptExecuteWithLib(`return env.hasnumber("n2");`, [])).toBe(true);
60
+ expect(await js.JavascriptExecuteWithLib(`return env.hasstring("s1");`, [])).toBe(true);
61
+ expect(await js.JavascriptExecuteWithLib(`return env.hasboolean("b1");`, [])).toBe(true);
62
+ expect(await js.JavascriptExecuteWithLib(`return env.hasnumber("nnn");`, [])).toBe(false);
63
+ expect(await js.JavascriptExecuteWithLib(`return env.hasstring("sss");`, [])).toBe(false);
64
+ expect(await js.JavascriptExecuteWithLib(`return env.hasboolean("bbb");`, [])).toBe(false);
65
+ });
75
66
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -28,7 +28,7 @@ describe("Express Test", () => {
28
28
  description: "This is a test task",
29
29
  setupjob: false,
30
30
  cronjob: cronjob ? true : false,
31
- cronjobKey: cronjob !== null && cronjob !== void 0 ? cronjob : "",
31
+ cronjobKey: cronjob ?? "",
32
32
  multi: false,
33
33
  multiKey: "",
34
34
  properties: property,
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/tsconfig.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES2015",
4
- "module": "commonjs",
3
+ "target": "es2024",
4
+ "module": "nodenext",
5
+ "moduleResolution": "nodenext",
5
6
  "strict": true,
7
+ "declaration": true,
6
8
  "esModuleInterop": true,
7
9
  "resolveJsonModule": true,
8
10
  "skipLibCheck": false,
9
11
  "forceConsistentCasingInFileNames": true,
10
12
  "outDir": "dist",
13
+ "rootDir": "src",
11
14
  "allowJs": true,
12
15
  "removeComments": true,
13
- "noImplicitAny": false,
14
- }
16
+ "noImplicitAny": false
17
+ },
18
+ "exclude": ["coverage", "test", "index.ts", "jest.config.js", "dist"]
15
19
  }
@@ -1,8 +0,0 @@
1
- "use strict";
2
- module.exports = {
3
- verbose: true,
4
- testEnvironment: "node",
5
- transform: {
6
- "^.+\.tsx?$": ["ts-jest", {}],
7
- }
8
- };
@@ -1,383 +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
- 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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.ClientAnalysis = void 0;
46
- const child_process_1 = require("child_process");
47
- const interface_1 = require("../interface");
48
- const client_1 = require("./client");
49
- const execute_1 = require("./execute");
50
- const shell_1 = require("./shell");
51
- const fs_1 = require("fs");
52
- const path = __importStar(require("path"));
53
- const os = __importStar(require("os"));
54
- class ClientAnalysis {
55
- constructor(_messager, _messager_log, _client) {
56
- this.resource_wanter = [];
57
- this.resource_thread = undefined;
58
- this.resource_cache = undefined;
59
- this.analysis = (h, source) => {
60
- const typeMap = {
61
- 'execute_job': this.execute_job,
62
- 'release': this.release,
63
- 'stop_job': this.stop_all,
64
- 'set_database': this.set_database,
65
- 'set_libs': this.set_libs,
66
- 'shell_folder': this.shell.shell_folder,
67
- 'open_shell': this.shell.open_shell,
68
- 'close_shell': this.shell.close_shell,
69
- 'enter_shell': this.shell.enter_shell,
70
- 'resource_start': this.resource_start,
71
- 'resource_end': this.resource_end,
72
- 'ping': this.pong,
73
- 'plugin_info': this.plugin_info,
74
- 'plugin_download': this.plugin_download,
75
- 'plugin_remove': this.plugin_remove,
76
- };
77
- if (h == undefined) {
78
- this.messager_log('[Client Analysis] Analysis Failed, Value is undefined');
79
- return 1;
80
- }
81
- if (h.message != undefined && h.message.length > 0) {
82
- this.messager_log(`[Client Analysis] ${h.message}`);
83
- }
84
- if (h.data == undefined) {
85
- this.messager_log('[Client Analysis] Analysis Warn, Data is undefined');
86
- h.data = 0;
87
- }
88
- if (typeMap.hasOwnProperty(h.name)) {
89
- const castingFunc = typeMap[h.name];
90
- castingFunc(h.data, source, h.channel);
91
- return 0;
92
- }
93
- else {
94
- this.messager_log(`[Client Analysis] Analysis Failed, Unknowed header, name: ${h.name}, meta: ${h.meta}`);
95
- return 2;
96
- }
97
- };
98
- this.execute_job = (job, source, channel) => {
99
- if (channel == undefined)
100
- return;
101
- const target = this.exec_checker(channel);
102
- target.execute_job(job, source);
103
- };
104
- this.release = (dummy, source, channel) => {
105
- if (channel == undefined)
106
- return;
107
- const index = this.exec.findIndex(x => x.uuid == channel);
108
- if (index == -1)
109
- return;
110
- this.exec.splice(index, 1);
111
- };
112
- this.set_database = (data, source, channel) => {
113
- if (channel == undefined)
114
- return;
115
- const target = this.exec_checker(channel);
116
- target.set_database(data);
117
- };
118
- this.set_libs = (data, source, channel) => {
119
- if (channel == undefined)
120
- return;
121
- const target = this.exec_checker(channel);
122
- target.set_libs(data);
123
- };
124
- this.exec_checker = (uuid) => {
125
- let r = undefined;
126
- const index = this.exec.findIndex(x => x.uuid == uuid);
127
- if (index == -1) {
128
- r = new execute_1.ClientExecute(uuid, this.messager, this.messager_log, this.client);
129
- this.exec.push(r);
130
- }
131
- else {
132
- r = this.exec[index];
133
- }
134
- return r;
135
- };
136
- this.pong = (data, source) => {
137
- const h = { name: 'pong', data: data };
138
- source.send(JSON.stringify(h));
139
- };
140
- this.plugin_info = (data, source) => {
141
- const pat = path.join(os.homedir(), interface_1.DATA_FOLDER, "plugin.json");
142
- if ((0, fs_1.existsSync)(pat)) {
143
- const p = JSON.parse((0, fs_1.readFileSync)(pat).toString());
144
- const h = { name: 'plugin_info_reply', data: p.plugins };
145
- source.send(JSON.stringify(h));
146
- }
147
- else {
148
- const p = { plugins: [] };
149
- const h = { name: 'plugin_info_reply', data: p.plugins };
150
- (0, fs_1.writeFileSync)(pat, JSON.stringify(p));
151
- source.send(JSON.stringify(h));
152
- }
153
- };
154
- this.get_releases = (repo, token) => __awaiter(this, void 0, void 0, function* () {
155
- const qu = yield fetch(`https://api.github.com/repos/${repo}/releases`, {
156
- headers: {
157
- Authorization: token ? `token ${token}` : '',
158
- Accept: "application/vnd.github.v3.raw",
159
- }
160
- });
161
- return qu.text();
162
- });
163
- this.filterout = (repo, token, version, filename) => __awaiter(this, void 0, void 0, function* () {
164
- const text = yield this.get_releases(repo, token);
165
- const json = JSON.parse(text);
166
- const v = json.find(x => x.tag_name == version);
167
- if (!v)
168
- return;
169
- const f = v.assets.find(x => x.name == filename);
170
- if (!f)
171
- return;
172
- return f.id;
173
- });
174
- this.write_plugin = (t, plugin, source) => {
175
- const list = this.client.plugins.plugins;
176
- const index = list.findIndex(x => x.name == plugin.name);
177
- plugin.token = t ? [t] : [];
178
- plugin.progress = 0;
179
- if (index == -1) {
180
- list.push(plugin);
181
- }
182
- else {
183
- list[index] = plugin;
184
- }
185
- this.client.savePlugin();
186
- this.plugin_info(0, source);
187
- };
188
- this.finish_plugin = (plugin, source) => {
189
- const list = this.client.plugins.plugins;
190
- const index = list.findIndex(x => x.name == plugin.name);
191
- plugin.progress = 1;
192
- if (index == -1) {
193
- list.push(plugin);
194
- }
195
- else {
196
- list[index] = plugin;
197
- }
198
- this.client.savePlugin();
199
- this.plugin_info(0, source);
200
- };
201
- this.plugin_download = (plugin, source) => __awaiter(this, void 0, void 0, function* () {
202
- const target = plugin.contents.find(x => x.arch == process.arch && x.platform == process.platform);
203
- if (target == undefined) {
204
- this.messager_log(`[Plugin] Cannot find target plugin for ${plugin.name} on ${process.platform} ${process.arch}`);
205
- return;
206
- }
207
- const links = target.url.split('/');
208
- const filename = links[links.length - 1];
209
- const version = links[links.length - 2];
210
- const REPO = `${links[3]}/${links[4]}`;
211
- const dir = path.join(os.homedir(), interface_1.DATA_FOLDER, "exe");
212
- if (!(0, fs_1.existsSync)(dir))
213
- (0, fs_1.mkdirSync)(dir, { recursive: true });
214
- let req = {};
215
- const tokens = [undefined, ...plugin.token];
216
- const fileStream = (0, fs_1.createWriteStream)(path.join(dir, target.filename), { flags: 'a' });
217
- let pass = false;
218
- for (let t of tokens) {
219
- if (pass)
220
- break;
221
- try {
222
- const id = yield this.filterout(REPO, t, version, filename);
223
- req = {
224
- method: 'GET',
225
- credentials: 'include',
226
- headers: {
227
- Authorization: t ? `token ${t}` : '',
228
- Accept: "application/octet-stream"
229
- }
230
- };
231
- const url = `https://api.github.com/repos/${REPO}/releases/assets/${id}`;
232
- fetch(url, req).then((res) => __awaiter(this, void 0, void 0, function* () {
233
- if (!res.ok) {
234
- throw new Error(`Failed to download file: ${res.status} ${res.statusText}`);
235
- }
236
- this.write_plugin(t, plugin, source);
237
- return res.blob();
238
- })).then(blob => {
239
- return blob.stream().getReader().read();
240
- })
241
- .then(reader => {
242
- if (!reader.done) {
243
- fileStream.write(Buffer.from(reader.value));
244
- }
245
- }).finally(() => {
246
- this.messager_log(`[Plugin] Downloaded ${plugin.name} successfully`);
247
- fileStream.end();
248
- if (process.platform == 'linux') {
249
- (0, child_process_1.exec)(`chmod +x ${path.join(dir, target.filename)}`, (err) => {
250
- this.messager_log(`[Plugin] Permission failed ${err === null || err === void 0 ? void 0 : err.message}`);
251
- });
252
- }
253
- this.finish_plugin(plugin, source);
254
- pass = true;
255
- });
256
- }
257
- catch (err) {
258
- this.messager_log(`[Plugin] Download failed for ${plugin.name}: ${err.message}`);
259
- }
260
- }
261
- });
262
- this.plugin_remove = (plugin, source) => {
263
- this.client.plugins.plugins = this.client.plugins.plugins.filter(x => x.name != plugin.name);
264
- this.client.savePlugin();
265
- const dir = path.join(os.homedir(), interface_1.DATA_FOLDER, "exe");
266
- if (!(0, fs_1.existsSync)(dir))
267
- (0, fs_1.mkdirSync)(dir, { recursive: true });
268
- plugin.contents.forEach(x => {
269
- if ((0, fs_1.existsSync)(path.join(dir, x.filename))) {
270
- (0, fs_1.rmSync)(path.join(dir, x.filename));
271
- }
272
- });
273
- this.plugin_info(0, source);
274
- };
275
- this.resource_start = (data, source) => {
276
- this.resource_wanter.push(source);
277
- this.messager_log(`Register resource_wanter!, count: ${this.resource_wanter.length}`);
278
- if (this.resource_cache != undefined)
279
- source.send(JSON.stringify(this.resource_cache));
280
- };
281
- this.resource_end = (data, source) => {
282
- const index = this.resource_wanter.findIndex(x => x == source);
283
- if (index != -1) {
284
- this.resource_wanter.splice(index, 1);
285
- this.messager_log(`UnRegister resource_wanter!, count: ${this.resource_wanter.length}`);
286
- }
287
- };
288
- this.update = (client) => {
289
- this.resource_require();
290
- if (this.resource_cache != undefined) {
291
- this.resource_wanter.forEach(x => x.send(JSON.stringify(this.resource_cache)));
292
- }
293
- };
294
- this.disconnect = (source) => {
295
- this.shell.disconnect(source);
296
- this.exec.forEach(x => x.stop_job());
297
- };
298
- this.stop_all = () => {
299
- this.exec.forEach(x => x.stop_job());
300
- };
301
- this.destroy = () => {
302
- if (this.resource_thread != undefined)
303
- this.resource_thread.kill();
304
- };
305
- this.resource_require = () => {
306
- var _a, _b, _c, _d;
307
- if (this.resource_thread != undefined)
308
- return;
309
- const shouldRun = this.resource_thread == undefined && (this.resource_cache == undefined || this.resource_wanter.length > 0);
310
- if (!shouldRun)
311
- return;
312
- this.resource_thread = (0, child_process_1.spawn)(client_1.Client.workerPath(), [], {
313
- stdio: ['inherit', 'pipe', 'pipe'],
314
- shell: true,
315
- windowsHide: true,
316
- env: Object.assign(Object.assign({}, process.env), { type: "RESOURCE", cache: this.resource_cache == undefined ? undefined : JSON.stringify(this.resource_cache.data) })
317
- });
318
- let k = "";
319
- const workerFeedbackExec = (str) => {
320
- try {
321
- const msg = JSON.parse(str);
322
- if (msg.name == 'messager') {
323
- this.messager(msg.data, "RESOURCE");
324
- }
325
- else if (msg.name == 'messager_log') {
326
- this.messager_log(msg.data, "RESOURCE");
327
- }
328
- else if (msg.name == 'resource') {
329
- const h = {
330
- name: 'system_info',
331
- data: msg.data
332
- };
333
- this.resource_cache = h;
334
- this.resource_wanter.forEach(x => x.send(JSON.stringify(h)));
335
- }
336
- else if (msg.name == 'error') {
337
- if (msg.data instanceof String)
338
- this.messager_log(msg.data.toString(), "RESOURCE");
339
- else
340
- this.messager_log(JSON.stringify(msg.data), "RESOURCE");
341
- }
342
- }
343
- catch (err) {
344
- console.log("str: " + str);
345
- console.log(err.name + "\n" + err.message);
346
- }
347
- };
348
- const workerFeedback = (str) => {
349
- for (let i = 0; i < str.length; i++) {
350
- if (str[i] != '\n')
351
- k += str[i];
352
- else {
353
- workerFeedbackExec(k);
354
- k = '';
355
- }
356
- }
357
- };
358
- this.resource_thread.on('error', (err) => {
359
- this.messager_log(`[Worker Error] ${err}`);
360
- });
361
- this.resource_thread.on('exit', (code, signal) => {
362
- this.resource_thread = undefined;
363
- });
364
- this.resource_thread.on('message', (message, sendHandle) => {
365
- workerFeedback(message.toString());
366
- });
367
- (_a = this.resource_thread.stdout) === null || _a === void 0 ? void 0 : _a.setEncoding('utf8');
368
- (_b = this.resource_thread.stdout) === null || _b === void 0 ? void 0 : _b.on('data', (chunk) => {
369
- workerFeedback(chunk.toString());
370
- });
371
- (_c = this.resource_thread.stderr) === null || _c === void 0 ? void 0 : _c.setEncoding('utf8');
372
- (_d = this.resource_thread.stderr) === null || _d === void 0 ? void 0 : _d.on('data', (chunk) => {
373
- workerFeedback(chunk.toString());
374
- });
375
- };
376
- this.client = _client;
377
- this.messager = _messager;
378
- this.messager_log = _messager_log;
379
- this.shell = new shell_1.ClientShell(_messager, _messager_log, this.client);
380
- this.exec = [];
381
- }
382
- }
383
- exports.ClientAnalysis = ClientAnalysis;