From f63a67e341453f8b786ba3c8387a0c65f5eea22d Mon Sep 17 00:00:00 2001 From: yushen Date: Wed, 4 Feb 2026 14:16:59 +0800 Subject: [PATCH] refactor(hub): improve device whitelist persistence format - Rename storage path from ~/.super-multica/devices/ to ~/.super-multica/client-devices/ for clarity - Change JSON format from bare array to { version, devices[] } dict for future extensibility - Auto-migrate legacy array format on load Co-Authored-By: Claude Opus 4.5 --- src/hub/device-store.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/hub/device-store.ts b/src/hub/device-store.ts index 6ce2e324..1519b812 100644 --- a/src/hub/device-store.ts +++ b/src/hub/device-store.ts @@ -25,7 +25,12 @@ export interface DeviceEntry { // ============ Persistence ============ -const DEVICES_DIR = join(DATA_DIR, "devices"); +interface WhitelistFile { + version: number; + devices: DeviceEntry[]; +} + +const DEVICES_DIR = join(DATA_DIR, "client-devices"); const DEVICES_FILE = join(DEVICES_DIR, "whitelist.json"); function ensureDir(): void { @@ -37,7 +42,10 @@ function ensureDir(): void { function loadDevices(): DeviceEntry[] { if (!existsSync(DEVICES_FILE)) return []; try { - return JSON.parse(readFileSync(DEVICES_FILE, "utf-8")) as DeviceEntry[]; + const raw = JSON.parse(readFileSync(DEVICES_FILE, "utf-8")); + // Migrate legacy array format + if (Array.isArray(raw)) return raw as DeviceEntry[]; + return (raw as WhitelistFile).devices ?? []; } catch { return []; } @@ -45,7 +53,8 @@ function loadDevices(): DeviceEntry[] { function saveDevices(devices: DeviceEntry[]): void { ensureDir(); - writeFileSync(DEVICES_FILE, JSON.stringify(devices, null, 2), "utf-8"); + const data: WhitelistFile = { version: 1, devices }; + writeFileSync(DEVICES_FILE, JSON.stringify(data, null, 2), "utf-8"); } // ============ DeviceStore ============