feat: 支持 macOS 设备 GUID 管理与修正 Linux global 路径 (#2099)
* 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 通过。
This commit is contained in:
1 parent
6797143b04
commit
7471e3ecd6
11 files changed
+1534
-47
No files matched your search
@@ -41,6 +41,7 @@ import { createOfflineRecovery } from '@/napcat-core/helper/offline-recovery';
|
||||
import { QQBasicInfoWrapper } from '@/napcat-core/helper/qq-basic-info';
|
||||
import { statusHelperSubscription } from '@/napcat-core/helper/status';
|
||||
import { applyPendingUpdates } from '@/napcat-webui-backend/src/api/UpdateNapCat';
|
||||
import { migrateLegacyGlobalPath } from './global-migrate';
|
||||
import { connectToNamedPipe } from './pipe';
|
||||
|
||||
// NapCat Shell App ES 入口文件
|
||||
@@ -64,7 +65,10 @@ function getDataPaths (wrapper: WrapperNodeApi): [string, string] {
|
||||
dataPath = path.resolve(os.homedir(), './.config/QQ');
|
||||
fs.mkdirSync(dataPath, { recursive: true });
|
||||
}
|
||||
const dataPathGlobal = path.resolve(dataPath, './nt_qq/global');
|
||||
// Linux: global 直接位于数据目录下; Windows: global 位于 nt_qq 子目录下
|
||||
const dataPathGlobal = os.platform() === 'linux'
|
||||
? path.resolve(dataPath, './global')
|
||||
: path.resolve(dataPath, './nt_qq/global');
|
||||
return [dataPath, dataPathGlobal];
|
||||
}
|
||||
|
||||
@@ -714,6 +718,7 @@ export async function NCoreInitShell () {
|
||||
}
|
||||
}
|
||||
const [dataPath, dataPathGlobal] = getDataPaths(wrapper);
|
||||
migrateLegacyGlobalPath(dataPath, dataPathGlobal, logger);
|
||||
WebUiDataRuntime.setQQDataPath(dataPath);
|
||||
const systemPlatform = getPlatformType();
|
||||
|
||||
|
||||
Reference in new issue
Block a user