@maiyunnet/kebab 2.0.7 → 2.0.9

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 (83) hide show
  1. package/index.d.ts +11 -1
  2. package/index.js +13 -1
  3. package/lib/buffer.d.ts +25 -0
  4. package/lib/buffer.js +30 -5
  5. package/lib/captcha.d.ts +15 -0
  6. package/lib/captcha.js +20 -0
  7. package/lib/consistent.d.ts +51 -0
  8. package/lib/consistent.js +59 -0
  9. package/lib/core.d.ts +134 -0
  10. package/lib/core.js +176 -0
  11. package/lib/crypto.d.ts +75 -6
  12. package/lib/crypto.js +206 -38
  13. package/lib/db.d.ts +104 -0
  14. package/lib/db.js +126 -0
  15. package/lib/dns.d.ts +51 -0
  16. package/lib/dns.js +54 -2
  17. package/lib/fs.d.ts +100 -0
  18. package/lib/fs.js +118 -0
  19. package/lib/jwt.d.ts +43 -0
  20. package/lib/jwt.js +45 -0
  21. package/lib/kv.d.ts +362 -0
  22. package/lib/kv.js +377 -0
  23. package/lib/lan.d.ts +6 -0
  24. package/lib/lan.js +7 -0
  25. package/lib/net/formdata.d.ts +38 -0
  26. package/lib/net/formdata.js +43 -0
  27. package/lib/net/request.d.ts +62 -0
  28. package/lib/net/request.js +57 -0
  29. package/lib/net/response.d.ts +21 -0
  30. package/lib/net/response.js +16 -0
  31. package/lib/net.d.ts +86 -0
  32. package/lib/net.js +140 -0
  33. package/lib/s3.d.ts +52 -0
  34. package/lib/s3.js +51 -0
  35. package/lib/scan.d.ts +52 -0
  36. package/lib/scan.js +84 -0
  37. package/lib/session.d.ts +31 -0
  38. package/lib/session.js +52 -1
  39. package/lib/sql.d.ts +176 -0
  40. package/lib/sql.js +287 -2
  41. package/lib/ssh/sftp.d.ts +106 -0
  42. package/lib/ssh/sftp.js +106 -0
  43. package/lib/ssh/shell.d.ts +37 -0
  44. package/lib/ssh/shell.js +31 -0
  45. package/lib/ssh.d.ts +32 -0
  46. package/lib/ssh.js +32 -0
  47. package/lib/text.d.ts +131 -0
  48. package/lib/text.js +188 -0
  49. package/lib/time.d.ts +53 -0
  50. package/lib/time.js +55 -0
  51. package/lib/ws.d.ts +68 -0
  52. package/lib/ws.js +74 -0
  53. package/lib/zip.d.ts +53 -0
  54. package/lib/zip.js +73 -0
  55. package/lib/zlib.d.ts +76 -0
  56. package/lib/zlib.js +78 -0
  57. package/main.d.ts +5 -0
  58. package/main.js +12 -0
  59. package/package.json +3 -2
  60. package/sys/child.js +104 -0
  61. package/sys/cmd.js +28 -0
  62. package/sys/ctr.d.ts +166 -0
  63. package/sys/ctr.js +177 -0
  64. package/sys/master.js +63 -0
  65. package/sys/mod.d.ts +266 -0
  66. package/sys/mod.js +335 -0
  67. package/sys/route.d.ts +34 -0
  68. package/sys/route.js +164 -0
  69. package/www/example/ctr/test.d.ts +3 -0
  70. package/www/example/ctr/test.js +63 -1
  71. package/www/example/mod/test.js +14 -0
  72. package/www/example/mod/testdata.js +9 -0
  73. package/www/example/ws/test.js +1 -0
  74. package/.VSCodeCounter/2025-02-14_14-46-44/details.md +0 -82
  75. package/.VSCodeCounter/2025-02-14_14-46-44/diff-details.md +0 -15
  76. package/.VSCodeCounter/2025-02-14_14-46-44/diff.csv +0 -2
  77. package/.VSCodeCounter/2025-02-14_14-46-44/diff.md +0 -19
  78. package/.VSCodeCounter/2025-02-14_14-46-44/diff.txt +0 -22
  79. package/.VSCodeCounter/2025-02-14_14-46-44/results.csv +0 -69
  80. package/.VSCodeCounter/2025-02-14_14-46-44/results.json +0 -1
  81. package/.VSCodeCounter/2025-02-14_14-46-44/results.md +0 -48
  82. package/.VSCodeCounter/2025-02-14_14-46-44/results.txt +0 -118
  83. package/.vscode/tasks.json +0 -15
package/lib/ssh/sftp.d.ts CHANGED
@@ -1,7 +1,14 @@
1
+ /**
2
+ * Project: Kebab, User: JianSuoQiYue
3
+ * Date: 2019-6-10 12:06
4
+ * Last: 2020-4-11 09:28:11, 2022-09-11 17:15:38, 2023-4-24 21:43:42
5
+ */
1
6
  import * as stream from 'stream';
2
7
  import * as ssh2 from 'ssh2';
3
8
  export declare class Connection {
9
+ /** --- 连接对象 --- */
4
10
  private readonly _client;
11
+ /** --- 当前路径,以 / 结尾 --- */
5
12
  private _path;
6
13
  constructor(sftp: ssh2.SFTPWrapper, path: string);
7
14
  getContent(path: string, options?: {
@@ -13,28 +20,127 @@ export declare class Connection {
13
20
  'start'?: number;
14
21
  'end'?: number;
15
22
  }): Promise<string | null>;
23
+ /**
24
+ * --- 写入文件内容 ---
25
+ * @param path 文件路径
26
+ * @param data 要写入的内容
27
+ * @param options 选项
28
+ */
16
29
  putContent(path: string, data: string | Buffer, options?: ssh2.WriteFileOptions): Promise<boolean>;
30
+ /**
31
+ * --- 读取链接的 target ---
32
+ * @param path 要读取的路径
33
+ */
17
34
  readLink(path: string): Promise<string | null>;
35
+ /**
36
+ * --- 把源文件创建一个 link ---
37
+ * @param filePath 源文件
38
+ * @param linkPath 连接路径
39
+ */
18
40
  symlink(filePath: string, linkPath: string): Promise<boolean>;
41
+ /**
42
+ * --- 删除一个文件 ---
43
+ * @param path 要删除的文件路径
44
+ */
19
45
  unlink(path: string): Promise<boolean>;
46
+ /** --- unlink 的删除的 promise 实现 --- */
20
47
  private _unlink;
48
+ /**
49
+ * --- 获取对象是否存在,存在则返回 stats 对象,否则返回 null ---
50
+ * @param path 对象路径
51
+ */
21
52
  stats(path: string): Promise<ssh2.Stats | null>;
53
+ /**
54
+ * --- 判断是否是目录或目录是否存在,是的话返回 stats ---
55
+ * @param path 判断路径
56
+ */
22
57
  isDir(path: string): Promise<ssh2.Stats | false>;
58
+ /**
59
+ * --- 判断是否是文件或文件是否存在,是的话返回 stats ---
60
+ * @param path 判断路径
61
+ */
23
62
  isFile(path: string): Promise<ssh2.Stats | false>;
63
+ /**
64
+ * --- 深度创建目录,如果最末目录存在,则自动创建成功 ---
65
+ * @param path 要创建的路径,如 /a/b/c/
66
+ * @param mode 权限
67
+ */
24
68
  mkdir(path: string, mode?: number): Promise<boolean>;
69
+ /**
70
+ * --- 删除一个空目录 ---
71
+ * @param path 要删除的目录路径
72
+ */
25
73
  rmdir(path: string): Promise<boolean>;
74
+ /**
75
+ * --- Danger 危险:危险函数,尽量不要使用 ---
76
+ * --- This f**king is a dangerous function, please don't use it ---
77
+ * --- 删除一个非空目录 ---
78
+ */
26
79
  rmdirDeep(path: string): Promise<boolean>;
80
+ /**
81
+ * --- 修改权限 ---
82
+ * @param path 要修改的路径
83
+ * @param mode 权限
84
+ */
27
85
  chmod(path: string, mode: string | number): Promise<boolean>;
86
+ /**
87
+ * --- 重命名/移动 文件文件夹 ---
88
+ * @param oldPath 老名
89
+ * @param newPath 新名
90
+ */
28
91
  rename(oldPath: string, newPath: string): Promise<boolean>;
92
+ /**
93
+ * --- 获取文件夹下文件列表 ---
94
+ * @param path 文件夹路径
95
+ */
29
96
  readDir(path: string): Promise<ssh2.FileEntry[]>;
97
+ /**
98
+ * --- 读取文件流 ---
99
+ * @param path 文件地址
100
+ */
30
101
  createReadStream(path: string, options?: ssh2.ReadStreamOptions): stream.Readable;
102
+ /**
103
+ * --- 读取文件写入到流,并等待写入完成 ---
104
+ * @param path 文件地址
105
+ * @param destination 要写入的流
106
+ * @param options 写入后是否终止写入流,默认终止
107
+ */
31
108
  pipe<T extends NodeJS.WritableStream>(path: string, destination: T, options?: {
32
109
  'end'?: boolean;
33
110
  }): Promise<boolean>;
111
+ /**
112
+ * --- 创建写入文件的流 ---
113
+ * @param path 文件地址
114
+ * @param options 编码或配置
115
+ */
34
116
  createWriteStream(path: string, options?: BufferEncoding | ssh2.WriteStreamOptions): stream.Writable;
117
+ /**
118
+ * --- 获取当前目录,末尾不带 / ---
119
+ * @return string
120
+ */
35
121
  pwd(): string;
122
+ /**
123
+ * --- 下载文件到本地 ---
124
+ * @param remoteFile 远程路径
125
+ * @param localFile 本地路径
126
+ * @param options 选项
127
+ */
36
128
  downloadFile(remoteFile: string, localFile: string, options?: ssh2.TransferOptions): Promise<boolean>;
129
+ /**
130
+ * --- 上传本地文件到远程 ---
131
+ * @param localFile 本地绝对路径
132
+ * @param remoteFile
133
+ * @return bool
134
+ */
37
135
  uploadFile(localFile: string, remoteFile: string, options?: ssh2.TransferOptions): Promise<boolean>;
136
+ /**
137
+ * --- 进入一个目录(不存在也能进入,需要自行判断) ---
138
+ * --- 返回进入后的路径值 ---
139
+ * @param dir 相对路径或绝对路径
140
+ */
38
141
  cd(dir: string): string;
142
+ /**
143
+ * --- 关闭当前频道 ---
144
+ */
39
145
  close(): void;
40
146
  }
package/lib/ssh/sftp.js CHANGED
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.Connection = void 0;
37
+ // --- 库和定义 ---
37
38
  const core = __importStar(require("../../lib/core"));
38
39
  const text = __importStar(require("../../lib/text"));
39
40
  class Connection {
@@ -41,6 +42,11 @@ class Connection {
41
42
  this._client = sftp;
42
43
  this._path = path;
43
44
  }
45
+ /**
46
+ * --- 读取完整文件或一段 ---
47
+ * @param path 文件路径
48
+ * @param options 编码或选项
49
+ */
44
50
  getContent(path, options) {
45
51
  path = text.urlResolve(this._path, path);
46
52
  if (typeof options === 'string') {
@@ -102,6 +108,12 @@ class Connection {
102
108
  }
103
109
  });
104
110
  }
111
+ /**
112
+ * --- 写入文件内容 ---
113
+ * @param path 文件路径
114
+ * @param data 要写入的内容
115
+ * @param options 选项
116
+ */
105
117
  putContent(path, data, options = {}) {
106
118
  path = text.urlResolve(this._path, path);
107
119
  return new Promise((resolve) => {
@@ -115,6 +127,10 @@ class Connection {
115
127
  });
116
128
  });
117
129
  }
130
+ /**
131
+ * --- 读取链接的 target ---
132
+ * @param path 要读取的路径
133
+ */
118
134
  readLink(path) {
119
135
  path = text.urlResolve(this._path, path);
120
136
  return new Promise((resolve) => {
@@ -128,6 +144,11 @@ class Connection {
128
144
  });
129
145
  });
130
146
  }
147
+ /**
148
+ * --- 把源文件创建一个 link ---
149
+ * @param filePath 源文件
150
+ * @param linkPath 连接路径
151
+ */
131
152
  symlink(filePath, linkPath) {
132
153
  filePath = text.urlResolve(this._path, filePath);
133
154
  linkPath = text.urlResolve(this._path, linkPath);
@@ -142,6 +163,10 @@ class Connection {
142
163
  });
143
164
  });
144
165
  }
166
+ /**
167
+ * --- 删除一个文件 ---
168
+ * @param path 要删除的文件路径
169
+ */
145
170
  async unlink(path) {
146
171
  path = text.urlResolve(this._path, path);
147
172
  for (let i = 0; i < 2; ++i) {
@@ -153,6 +178,7 @@ class Connection {
153
178
  }
154
179
  return this._unlink(path);
155
180
  }
181
+ /** --- unlink 的删除的 promise 实现 --- */
156
182
  _unlink(path) {
157
183
  return new Promise((resolve) => {
158
184
  this._client.unlink(path, function (err) {
@@ -165,6 +191,10 @@ class Connection {
165
191
  });
166
192
  });
167
193
  }
194
+ /**
195
+ * --- 获取对象是否存在,存在则返回 stats 对象,否则返回 null ---
196
+ * @param path 对象路径
197
+ */
168
198
  stats(path) {
169
199
  path = text.urlResolve(this._path, path);
170
200
  return new Promise((resolve) => {
@@ -178,6 +208,10 @@ class Connection {
178
208
  });
179
209
  });
180
210
  }
211
+ /**
212
+ * --- 判断是否是目录或目录是否存在,是的话返回 stats ---
213
+ * @param path 判断路径
214
+ */
181
215
  async isDir(path) {
182
216
  const pstats = await this.stats(path);
183
217
  if (!pstats?.isDirectory()) {
@@ -185,6 +219,10 @@ class Connection {
185
219
  }
186
220
  return pstats;
187
221
  }
222
+ /**
223
+ * --- 判断是否是文件或文件是否存在,是的话返回 stats ---
224
+ * @param path 判断路径
225
+ */
188
226
  async isFile(path) {
189
227
  const pstats = await this.stats(path);
190
228
  if (!pstats?.isFile()) {
@@ -192,6 +230,11 @@ class Connection {
192
230
  }
193
231
  return pstats;
194
232
  }
233
+ /**
234
+ * --- 深度创建目录,如果最末目录存在,则自动创建成功 ---
235
+ * @param path 要创建的路径,如 /a/b/c/
236
+ * @param mode 权限
237
+ */
195
238
  async mkdir(path, mode = 0o755) {
196
239
  path = text.urlResolve(this._path, path);
197
240
  if (await this.isDir(path)) {
@@ -220,6 +263,10 @@ class Connection {
220
263
  }
221
264
  return true;
222
265
  }
266
+ /**
267
+ * --- 删除一个空目录 ---
268
+ * @param path 要删除的目录路径
269
+ */
223
270
  async rmdir(path) {
224
271
  path = text.urlResolve(this._path, path);
225
272
  if (!(await this.isDir(path))) {
@@ -236,6 +283,11 @@ class Connection {
236
283
  });
237
284
  });
238
285
  }
286
+ /**
287
+ * --- Danger 危险:危险函数,尽量不要使用 ---
288
+ * --- This f**king is a dangerous function, please don't use it ---
289
+ * --- 删除一个非空目录 ---
290
+ */
239
291
  async rmdirDeep(path) {
240
292
  path = text.urlResolve(this._path, path);
241
293
  if (!path.endsWith('/')) {
@@ -251,6 +303,7 @@ class Connection {
251
303
  return false;
252
304
  }
253
305
  if (stat.isDirectory()) {
306
+ // --- 目录 ---
254
307
  const rtn = await this.rmdirDeep(path + item.filename);
255
308
  if (!rtn) {
256
309
  return false;
@@ -265,6 +318,11 @@ class Connection {
265
318
  }
266
319
  return this.rmdir(path);
267
320
  }
321
+ /**
322
+ * --- 修改权限 ---
323
+ * @param path 要修改的路径
324
+ * @param mode 权限
325
+ */
268
326
  chmod(path, mode) {
269
327
  path = text.urlResolve(this._path, path);
270
328
  return new Promise((resolve) => {
@@ -278,6 +336,11 @@ class Connection {
278
336
  });
279
337
  });
280
338
  }
339
+ /**
340
+ * --- 重命名/移动 文件文件夹 ---
341
+ * @param oldPath 老名
342
+ * @param newPath 新名
343
+ */
281
344
  rename(oldPath, newPath) {
282
345
  oldPath = text.urlResolve(this._path, oldPath);
283
346
  newPath = text.urlResolve(this._path, newPath);
@@ -292,6 +355,10 @@ class Connection {
292
355
  });
293
356
  });
294
357
  }
358
+ /**
359
+ * --- 获取文件夹下文件列表 ---
360
+ * @param path 文件夹路径
361
+ */
295
362
  readDir(path) {
296
363
  path = text.urlResolve(this._path, path);
297
364
  return new Promise((resolve) => {
@@ -305,10 +372,20 @@ class Connection {
305
372
  });
306
373
  });
307
374
  }
375
+ /**
376
+ * --- 读取文件流 ---
377
+ * @param path 文件地址
378
+ */
308
379
  createReadStream(path, options) {
309
380
  path = text.urlResolve(this._path, path);
310
381
  return this._client.createReadStream(path, options);
311
382
  }
383
+ /**
384
+ * --- 读取文件写入到流,并等待写入完成 ---
385
+ * @param path 文件地址
386
+ * @param destination 要写入的流
387
+ * @param options 写入后是否终止写入流,默认终止
388
+ */
312
389
  pipe(path, destination, options = {}) {
313
390
  path = text.urlResolve(this._path, path);
314
391
  return new Promise((resolve) => {
@@ -319,6 +396,11 @@ class Connection {
319
396
  }).pipe(destination, options);
320
397
  });
321
398
  }
399
+ /**
400
+ * --- 创建写入文件的流 ---
401
+ * @param path 文件地址
402
+ * @param options 编码或配置
403
+ */
322
404
  createWriteStream(path, options) {
323
405
  if (typeof options === 'string') {
324
406
  options = {
@@ -330,9 +412,19 @@ class Connection {
330
412
  }
331
413
  return this._client.createWriteStream(path, options);
332
414
  }
415
+ /**
416
+ * --- 获取当前目录,末尾不带 / ---
417
+ * @return string
418
+ */
333
419
  pwd() {
334
420
  return this._path.slice(0, -1);
335
421
  }
422
+ /**
423
+ * --- 下载文件到本地 ---
424
+ * @param remoteFile 远程路径
425
+ * @param localFile 本地路径
426
+ * @param options 选项
427
+ */
336
428
  downloadFile(remoteFile, localFile, options = {}) {
337
429
  remoteFile = text.urlResolve(this._path, remoteFile);
338
430
  return new Promise((resolve) => {
@@ -346,6 +438,12 @@ class Connection {
346
438
  });
347
439
  });
348
440
  }
441
+ /**
442
+ * --- 上传本地文件到远程 ---
443
+ * @param localFile 本地绝对路径
444
+ * @param remoteFile
445
+ * @return bool
446
+ */
349
447
  uploadFile(localFile, remoteFile, options = {}) {
350
448
  remoteFile = text.urlResolve(this._path, remoteFile);
351
449
  return new Promise((resolve) => {
@@ -359,6 +457,11 @@ class Connection {
359
457
  });
360
458
  });
361
459
  }
460
+ /**
461
+ * --- 进入一个目录(不存在也能进入,需要自行判断) ---
462
+ * --- 返回进入后的路径值 ---
463
+ * @param dir 相对路径或绝对路径
464
+ */
362
465
  cd(dir) {
363
466
  this._path = text.urlResolve(this._path, dir);
364
467
  if (!this._path.endsWith('/')) {
@@ -366,6 +469,9 @@ class Connection {
366
469
  }
367
470
  return this._path;
368
471
  }
472
+ /**
473
+ * --- 关闭当前频道 ---
474
+ */
369
475
  close() {
370
476
  this._client.end();
371
477
  }
@@ -1,13 +1,50 @@
1
+ /**
2
+ * Project: Kebab, User: JianSuoQiYue
3
+ * Date: 2019-6-8 22:13
4
+ * Last: 2020-4-10 16:08:32, 2022-12-30 00:03:40, 2023-4-22 21:06:57
5
+ */
1
6
  import * as ssh2 from 'ssh2';
2
7
  export declare class Connection {
8
+ /** --- 连接对象 --- */
3
9
  private readonly _client;
4
10
  constructor(stream: ssh2.ClientChannel);
11
+ /**
12
+ * --- 发送指令 ---
13
+ * @param cmd 指令
14
+ * @param encoding 编码
15
+ */
5
16
  send(cmd: string | Buffer, encoding?: BufferEncoding): Promise<boolean>;
17
+ /**
18
+ * --- 发送带换行的内容(发送并执行) ---
19
+ * @param cmd 指令
20
+ * @param encoding 编码
21
+ */
6
22
  sendLine(cmd: string, encoding?: BufferEncoding): Promise<boolean>;
23
+ /**
24
+ * --- 发送 Enter 键 ---
25
+ */
7
26
  sendEnter(): Promise<boolean>;
27
+ /**
28
+ * --- 发送 Tab 键 ---
29
+ */
8
30
  sendTab(): Promise<boolean>;
31
+ /**
32
+ * --- 发送中断 ---
33
+ */
9
34
  sendCtrlC(): Promise<boolean>;
35
+ /**
36
+ * --- 关闭 shell ---
37
+ * @param cmd 命令
38
+ * @param encoding 编码
39
+ */
10
40
  close(cmd?: string | Buffer, encoding?: BufferEncoding): Promise<void>;
41
+ /**
42
+ * --- 获取返回值 ---
43
+ * @param tryCount 如果无知重试次数,1 次为 10 毫秒 ---
44
+ */
11
45
  getContent(tryCount?: number): Promise<Buffer>;
46
+ /**
47
+ * --- 获取响应读取流对象 ---
48
+ */
12
49
  getStream(): ssh2.ClientChannel;
13
50
  }
package/lib/ssh/shell.js CHANGED
@@ -39,6 +39,11 @@ class Connection {
39
39
  constructor(stream) {
40
40
  this._client = stream;
41
41
  }
42
+ /**
43
+ * --- 发送指令 ---
44
+ * @param cmd 指令
45
+ * @param encoding 编码
46
+ */
42
47
  send(cmd, encoding) {
43
48
  return new Promise((resolve) => {
44
49
  const cb = (e) => {
@@ -57,18 +62,37 @@ class Connection {
57
62
  }
58
63
  });
59
64
  }
65
+ /**
66
+ * --- 发送带换行的内容(发送并执行) ---
67
+ * @param cmd 指令
68
+ * @param encoding 编码
69
+ */
60
70
  async sendLine(cmd, encoding) {
61
71
  return this.send(cmd + '\n', encoding);
62
72
  }
73
+ /**
74
+ * --- 发送 Enter 键 ---
75
+ */
63
76
  async sendEnter() {
64
77
  return this.send('\n');
65
78
  }
79
+ /**
80
+ * --- 发送 Tab 键 ---
81
+ */
66
82
  async sendTab() {
67
83
  return this.send('\t');
68
84
  }
85
+ /**
86
+ * --- 发送中断 ---
87
+ */
69
88
  async sendCtrlC() {
70
89
  return this.send('\x03');
71
90
  }
91
+ /**
92
+ * --- 关闭 shell ---
93
+ * @param cmd 命令
94
+ * @param encoding 编码
95
+ */
72
96
  close(cmd, encoding) {
73
97
  return new Promise((resolve) => {
74
98
  if (encoding) {
@@ -83,6 +107,10 @@ class Connection {
83
107
  }
84
108
  });
85
109
  }
110
+ /**
111
+ * --- 获取返回值 ---
112
+ * @param tryCount 如果无知重试次数,1 次为 10 毫秒 ---
113
+ */
86
114
  async getContent(tryCount = 10) {
87
115
  let nowCount = 0;
88
116
  let data = Buffer.from('');
@@ -102,6 +130,9 @@ class Connection {
102
130
  }
103
131
  return data;
104
132
  }
133
+ /**
134
+ * --- 获取响应读取流对象 ---
135
+ */
105
136
  getStream() {
106
137
  return this._client;
107
138
  }
package/lib/ssh.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Project: Kebab, User: JianSuoQiYue
3
+ * Date: 2019-6-8 21:34:35
4
+ * Last: 2020-04-06 21:22:46, 2022-09-12 00:19:05, 2024-3-4 14:46:11
5
+ */
1
6
  import * as ssh2 from 'ssh2';
2
7
  import * as shell from './ssh/shell';
3
8
  import * as sftp from './ssh/sftp';
@@ -9,16 +14,43 @@ interface IExtOptions {
9
14
  'password': string;
10
15
  };
11
16
  }
17
+ /** 主连接对象 */
12
18
  export declare class Connection {
19
+ /** --- SSH 对象 --- */
13
20
  private readonly _client;
21
+ /** --- 中转服务器 --- */
14
22
  private _mclient?;
15
23
  constructor();
24
+ /**
25
+ * --- 发起连接 ---
26
+ * @param opt 选项
27
+ */
16
28
  connect(opt: ssh2.ConnectConfig & IExtOptions): Promise<boolean>;
29
+ /**
30
+ * --- 断开此连接 socket ---
31
+ */
17
32
  disconnect(): void;
33
+ /**
34
+ * --- 执行一个命令并获取返回值,请不要在此执行无尽命令,否则获取不到返回值 ---
35
+ * @param command 命令内容
36
+ */
18
37
  exec(command: string): Promise<Buffer | false>;
38
+ /**
39
+ * --- 获取 Shell 执行对象 ---
40
+ */
19
41
  getShell(): Promise<shell.Connection | null>;
42
+ /**
43
+ * --- 获取 Sftp 执行对象 ---
44
+ */
20
45
  getSftp(): Promise<sftp.Connection | null>;
46
+ /**
47
+ * --- 直接获取原生 shell stream 对象 ---
48
+ */
21
49
  getStream(): Promise<ssh2.ClientChannel | null>;
22
50
  }
51
+ /**
52
+ * --- 创建一个 SSH 连接 ---
53
+ * @param opt 选项
54
+ */
23
55
  export declare function get(opt: ssh2.ConnectConfig & IExtOptions): Promise<Connection | null>;
24
56
  export {};
package/lib/ssh.js CHANGED
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
+ /**
3
+ * Project: Kebab, User: JianSuoQiYue
4
+ * Date: 2019-6-8 21:34:35
5
+ * Last: 2020-04-06 21:22:46, 2022-09-12 00:19:05, 2024-3-4 14:46:11
6
+ */
2
7
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
8
  if (k2 === undefined) k2 = k;
4
9
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -35,13 +40,20 @@ var __importStar = (this && this.__importStar) || (function () {
35
40
  Object.defineProperty(exports, "__esModule", { value: true });
36
41
  exports.Connection = void 0;
37
42
  exports.get = get;
43
+ // --- 第三方 ---
38
44
  const ssh2 = __importStar(require("ssh2"));
45
+ // --- 自己 ---
39
46
  const shell = __importStar(require("./ssh/shell"));
40
47
  const sftp = __importStar(require("./ssh/sftp"));
48
+ /** 主连接对象 */
41
49
  class Connection {
42
50
  constructor() {
43
51
  this._client = new ssh2.Client();
44
52
  }
53
+ /**
54
+ * --- 发起连接 ---
55
+ * @param opt 选项
56
+ */
45
57
  connect(opt) {
46
58
  return new Promise((resolve) => {
47
59
  if (!opt.mproxy) {
@@ -97,9 +109,16 @@ class Connection {
97
109
  }).connect(opt);
98
110
  });
99
111
  }
112
+ /**
113
+ * --- 断开此连接 socket ---
114
+ */
100
115
  disconnect() {
101
116
  this._client.end();
102
117
  }
118
+ /**
119
+ * --- 执行一个命令并获取返回值,请不要在此执行无尽命令,否则获取不到返回值 ---
120
+ * @param command 命令内容
121
+ */
103
122
  exec(command) {
104
123
  return new Promise((resolve) => {
105
124
  this._client.exec(command, function (err, channel) {
@@ -118,6 +137,9 @@ class Connection {
118
137
  });
119
138
  });
120
139
  }
140
+ /**
141
+ * --- 获取 Shell 执行对象 ---
142
+ */
121
143
  getShell() {
122
144
  return new Promise((resolve) => {
123
145
  this._client.shell(function (err, channel) {
@@ -129,6 +151,9 @@ class Connection {
129
151
  });
130
152
  });
131
153
  }
154
+ /**
155
+ * --- 获取 Sftp 执行对象 ---
156
+ */
132
157
  getSftp() {
133
158
  return new Promise((resolve) => {
134
159
  this._client.sftp((err, ssftp) => {
@@ -152,6 +177,9 @@ class Connection {
152
177
  });
153
178
  });
154
179
  }
180
+ /**
181
+ * --- 直接获取原生 shell stream 对象 ---
182
+ */
155
183
  getStream() {
156
184
  return new Promise((resolve) => {
157
185
  this._client.shell(function (err, stream) {
@@ -164,6 +192,10 @@ class Connection {
164
192
  }
165
193
  }
166
194
  exports.Connection = Connection;
195
+ /**
196
+ * --- 创建一个 SSH 连接 ---
197
+ * @param opt 选项
198
+ */
167
199
  async function get(opt) {
168
200
  const conn = new Connection();
169
201
  const rtn = await conn.connect(opt);