@wendongfly/myhi 1.0.28 → 1.0.29

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 (2) hide show
  1. package/bin/myhi.js +28 -8
  2. package/package.json +1 -1
package/bin/myhi.js CHANGED
@@ -104,18 +104,33 @@ if (cmd === 'attach') {
104
104
  }
105
105
 
106
106
  } else if (cmd === 'user') {
107
- const { loadUsers, listUsers, addUser, removeUser } = await import('../src/roles.js');
108
- loadUsers();
107
+ // 用户管理:直接读写 ~/.myhi/users.json,不依赖 src/
108
+ const { existsSync } = await import('fs');
109
+ const usersFile = join(configDir, 'users.json');
110
+
111
+ function loadUsersFile() {
112
+ try {
113
+ if (existsSync(usersFile)) return JSON.parse(readFileSync(usersFile, 'utf8'));
114
+ } catch {}
115
+ return { users: {} };
116
+ }
117
+ function saveUsersFile(data) {
118
+ mkdirSync(configDir, { recursive: true });
119
+ writeFileSync(usersFile, JSON.stringify(data, null, 2), { mode: 0o600 });
120
+ }
121
+
109
122
  const sub = args[args.indexOf('user') + 1] || process.argv[3];
110
123
  if (sub === 'list' || sub === 'ls') {
111
- const users = listUsers();
112
- if (users.length === 0) {
124
+ const data = loadUsersFile();
125
+ const entries = Object.entries(data.users || {});
126
+ if (entries.length === 0) {
113
127
  console.log('[myhi] 还没有用户,使用 myhi user add <密码> <名称> <目录> 添加');
114
128
  } else {
115
129
  console.log('\n 密码\t\t名称\t\t目录');
116
130
  console.log(' ────\t\t────\t\t────');
117
- for (const u of users) {
118
- console.log(` ${u.password}\t\t${u.name}\t\t${u.dir}`);
131
+ for (const [pwd, info] of entries) {
132
+ const masked = pwd.slice(0, 2) + '*'.repeat(pwd.length - 2);
133
+ console.log(` ${masked}\t\t${info.name}\t\t${info.dir}`);
119
134
  }
120
135
  console.log();
121
136
  }
@@ -128,7 +143,9 @@ if (cmd === 'attach') {
128
143
  console.log('示例: myhi user add 1234 张三 D:\\project\\app1');
129
144
  process.exit(1);
130
145
  }
131
- addUser(pwd, name, dir);
146
+ const data = loadUsersFile();
147
+ data.users[pwd] = { name, dir };
148
+ saveUsersFile(data);
132
149
  console.log(`[myhi] 已添加用户 "${name}" (目录: ${dir})`);
133
150
  } else if (sub === 'remove' || sub === 'rm') {
134
151
  const pwd = process.argv[4];
@@ -136,7 +153,10 @@ if (cmd === 'attach') {
136
153
  console.log('用法: myhi user remove <密码>');
137
154
  process.exit(1);
138
155
  }
139
- if (removeUser(pwd)) {
156
+ const data = loadUsersFile();
157
+ if (data.users[pwd]) {
158
+ delete data.users[pwd];
159
+ saveUsersFile(data);
140
160
  console.log(`[myhi] 已删除用户`);
141
161
  } else {
142
162
  console.log('[myhi] 未找到该密码对应的用户');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wendongfly/myhi",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "Web-based terminal sharing with chat UI — control your terminal from phone via LAN/Tailscale",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",