* feat(webui): 支持 macOS 设备 GUID 管理与修正 Linux global 路径
Linux 的 global 目录直接位于数据根目录下(不再经过 nt_qq), 与 macOS 对齐;
新增 getGlobalDataPath 统一推导, 修正 Registry20/machine-info 在 Linux 下指向错误目录。
macOS 设备 GUID 实现(逆向自 wrapper.node, 对齐 qq_guid_tool):
- guid = MD5(machine_id[8] || sn)
- machineid-info 使用 QQ 私有 TEA 容器(16 轮, 大端), 密钥为 IOPlatformUUID 前 16 字节
- machine_id 优先读 machineid-info, 失败回退主网卡 MAC + 0000
- sn 优先 /dev/disk0 序列号, 回退 IOPlatformSerialNumber
- 新增 GetMacGUIDInfo / GetMacHardwareInfo / SetMacMachineId /
GetMacInfoBackups / CreateMacInfoBackup / RestoreMacInfoBackup / ResetMacDeviceID
- 前端 GUID 面板支持 macOS: 显示硬件信息, 编辑 machine_id 并实时预览 GUID, 备份/恢复/删除
* fix(webui): 加固 GUID 管理并补充 Linux global 路径迁移
按评审意见处理:
- Linux 迁移: 仅当 <dataPath>/global 不存在且 <dataPath>/nt_qq/global 存在时
搬运旧目录, 新目录已存在则保持原样; 逻辑抽到 global-migrate.ts 便于测试
- macOS 主网卡 MAC: 优先 en0, 再回退父级 IOEthernetController 上的
IOMACAddress, 整条链路判空容错
- 恢复接口防目录穿越: 备份名必须命中白名单且匹配 .bak.<时间戳> 格式,
写入前校验内容合法性 (Registry20 / machine-info / TEA 容器)
- SN 留空语义统一为"沿用当前生效值", 前后端预览与落库一致
- 前端保存按钮 dirty 判定纳入 SN
- 备份命名加毫秒时间戳与随机后缀, COPYFILE_EXCL 落盘, 杜绝同秒覆盖
- 硬件查询改为异步 execFile 并加进程内缓存, 不再阻塞事件循环
测试: 新增 Linux 迁移 5 例与备份命名/穿越/内容校验用例,
全量 27 文件 256 例通过; tsc --noEmit 与 eslint 通过。
77 lines
3.1 KiB
TypeScript
77 lines
3.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { migrateLegacyGlobalPath } from '@/napcat-shell/global-migrate';
|
|
|
|
const noopLogger = { log: () => {}, logError: () => {} };
|
|
|
|
function withTempDir (fn: (dir: string) => void): void {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'napcat-migrate-test-'));
|
|
try {
|
|
fn(dir);
|
|
} finally {
|
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
}
|
|
|
|
describe('Linux legacy global migration', () => {
|
|
it('moves nt_qq/global to global when the new path is absent', () => {
|
|
withTempDir((dir) => {
|
|
const legacy = path.join(dir, 'nt_qq', 'global');
|
|
fs.mkdirSync(path.join(legacy, 'nt_data', 'msf'), { recursive: true });
|
|
fs.writeFileSync(path.join(legacy, 'nt_data', 'msf', 'machine-info'), Buffer.from('legacy-creds'));
|
|
const target = path.join(dir, 'global');
|
|
|
|
expect(migrateLegacyGlobalPath(dir, target, noopLogger, 'linux')).toBe(true);
|
|
expect(fs.existsSync(legacy)).toBe(false);
|
|
expect(fs.readFileSync(path.join(target, 'nt_data', 'msf', 'machine-info')).toString())
|
|
.toBe('legacy-creds');
|
|
});
|
|
});
|
|
|
|
it('does nothing when the new global path already exists (keeps both intact)', () => {
|
|
withTempDir((dir) => {
|
|
const legacy = path.join(dir, 'nt_qq', 'global');
|
|
const target = path.join(dir, 'global');
|
|
fs.mkdirSync(legacy, { recursive: true });
|
|
fs.mkdirSync(target, { recursive: true });
|
|
fs.writeFileSync(path.join(legacy, 'marker'), Buffer.from('legacy'));
|
|
fs.writeFileSync(path.join(target, 'marker'), Buffer.from('new'));
|
|
|
|
expect(migrateLegacyGlobalPath(dir, target, noopLogger, 'linux')).toBe(false);
|
|
expect(fs.readFileSync(path.join(legacy, 'marker')).toString()).toBe('legacy');
|
|
expect(fs.readFileSync(path.join(target, 'marker')).toString()).toBe('new');
|
|
});
|
|
});
|
|
|
|
it('does nothing when neither path exists', () => {
|
|
withTempDir((dir) => {
|
|
expect(migrateLegacyGlobalPath(dir, path.join(dir, 'global'), noopLogger, 'linux')).toBe(false);
|
|
expect(fs.existsSync(path.join(dir, 'global'))).toBe(false);
|
|
});
|
|
});
|
|
|
|
it('is idempotent across repeated startups', () => {
|
|
withTempDir((dir) => {
|
|
const legacy = path.join(dir, 'nt_qq', 'global');
|
|
fs.mkdirSync(legacy, { recursive: true });
|
|
fs.writeFileSync(path.join(legacy, 'login.db'), Buffer.from('creds'));
|
|
const target = path.join(dir, 'global');
|
|
|
|
expect(migrateLegacyGlobalPath(dir, target, noopLogger, 'linux')).toBe(true);
|
|
expect(migrateLegacyGlobalPath(dir, target, noopLogger, 'linux')).toBe(false);
|
|
expect(fs.readFileSync(path.join(target, 'login.db')).toString()).toBe('creds');
|
|
});
|
|
});
|
|
|
|
it('never touches non-Linux platforms', () => {
|
|
withTempDir((dir) => {
|
|
const legacy = path.join(dir, 'nt_qq', 'global');
|
|
fs.mkdirSync(legacy, { recursive: true });
|
|
expect(migrateLegacyGlobalPath(dir, path.join(dir, 'global'), noopLogger, 'win32')).toBe(false);
|
|
expect(fs.existsSync(legacy)).toBe(true);
|
|
});
|
|
});
|
|
});
|