mysshx 1.0.0 → 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.
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>mysshx - SSH 管理器</title>
7
- <script type="module" crossorigin src="/assets/index-bA2L5FBW.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-DjxXfsDs.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-DYP7pi_n.css">
9
9
  </head>
10
10
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysshx",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "SSH/SFTP 管理器:Node.js 后端 + MUI 前端 + SQLite 存储,可通过 npx 运行",
5
5
  "type": "module",
6
6
  "engines": {
package/readme.md ADDED
@@ -0,0 +1,7 @@
1
+ npm pack
2
+ npm login
3
+ npm publish
4
+
5
+ npx mysshx
6
+ npm i -g mysshx
7
+ mysshx
@@ -23,6 +23,31 @@ async function handle(ws, machineId) {
23
23
  return ws.close();
24
24
  }
25
25
 
26
+ let stream = null;
27
+ const pending = [];
28
+
29
+ const applyMessage = (msg) => {
30
+ if (!stream) return;
31
+ if (msg.type === 'input' && msg.data) {
32
+ stream.write(Buffer.from(msg.data, 'base64'));
33
+ } else if (msg.type === 'resize' && stream.setWindow) {
34
+ const cols = Math.max(1, msg.cols | 0);
35
+ const rows = Math.max(1, msg.rows | 0);
36
+ stream.setWindow(rows, cols, 0, 0);
37
+ }
38
+ };
39
+
40
+ ws.on('message', (raw) => {
41
+ let msg;
42
+ try {
43
+ msg = JSON.parse(raw.toString());
44
+ } catch {
45
+ return;
46
+ }
47
+ if (stream) applyMessage(msg);
48
+ else pending.push(msg);
49
+ });
50
+
26
51
  let client;
27
52
  try {
28
53
  client = await connectMachine(machine);
@@ -33,7 +58,7 @@ async function handle(ws, machineId) {
33
58
 
34
59
  client.shell(
35
60
  { term: 'xterm-256color', cols: 80, rows: 24 },
36
- (err, stream) => {
61
+ (err, s) => {
37
62
  if (err) {
38
63
  send(ws, { type: 'error', message: `打开终端失败: ${err.message}` });
39
64
  try {
@@ -42,6 +67,10 @@ async function handle(ws, machineId) {
42
67
  return ws.close();
43
68
  }
44
69
 
70
+ stream = s;
71
+ for (const msg of pending) applyMessage(msg);
72
+ pending.length = 0;
73
+
45
74
  send(ws, { type: 'status', status: 'connected', name: machine.name });
46
75
 
47
76
  const push = (data) => send(ws, { type: 'data', data: data.toString('base64') });
@@ -54,22 +83,6 @@ async function handle(ws, machineId) {
54
83
  } catch {}
55
84
  ws.close();
56
85
  });
57
-
58
- ws.on('message', (raw) => {
59
- let msg;
60
- try {
61
- msg = JSON.parse(raw.toString());
62
- } catch {
63
- return;
64
- }
65
- if (msg.type === 'input' && msg.data) {
66
- stream.write(Buffer.from(msg.data, 'base64'));
67
- } else if (msg.type === 'resize' && stream.setWindow) {
68
- const cols = Math.max(1, msg.cols | 0);
69
- const rows = Math.max(1, msg.rows | 0);
70
- stream.setWindow(rows, cols, 0, 0);
71
- }
72
- });
73
86
  }
74
87
  );
75
88