import Foundation // 主 app 与各扩展共享的后端坐标 + 控件专用设备会话标识。 enum CDropAPI { // 后端 / 引擎源(与 EngineController.engineURL 默认同源)。原生扩展无「同源」语境,须绝对 URL。 static let base = "https://drop.commilitia.net" private static let widgetDeviceIDKey = "cdrop.widget.device_id" // 控件专用设备会话的稳定 device_id(dev_ 前缀 + [A-Za-z0-9_-],见后端 validDeviceID)。存 // App Group UserDefaults,主 app 代铸控件会话与控件自刷共用同一身份。 static func widgetDeviceID() -> String { let defaults = UserDefaults(suiteName: AppGroup.identifier) ?? .standard if let existing = defaults.string(forKey: widgetDeviceIDKey) { return existing } let id = "dev_widget" + UUID().uuidString.replacingOccurrences(of: "-", with: "").prefix(16) defaults.set(id, forKey: widgetDeviceIDKey) return id } // 登出时清掉控件设备 id:下次登录(可能换账号)铸全新控件身份,避免复用旧 device_id 使新 // 账号的控件会话无设备行、不可在管理 UI 吊销(见审查 L2)。 static func clearWidgetDeviceID() { UserDefaults(suiteName: AppGroup.identifier)?.removeObject(forKey: widgetDeviceIDKey) } }