import Foundation /// 任务与工作台状态使用缓存读数;设备操作和准备页电量保留调用方请求。 enum DroneDockReadRequestPolicy { /// Debug 与 Release 使用相同规则,不改写创建、飞控或图传请求。 static func prepare(_ request: URLRequest) throws -> URLRequest { guard request.httpMethod == "GET", let url = request.url else { return request } let path = "/" + url.path.split(separator: "/").joined(separator: "/") let liveKey: String switch path { case "/api/app/airport/shooting": liveKey = "live_battery" case "/api/app/airport/status": liveKey = "live_metrics" default: return request } guard var components = URLComponents(url: url, resolvingAgainstBaseURL: false) else { throw APIError.invalidURL } var items = components.queryItems ?? [] items.removeAll { $0.name == liveKey } items.append(URLQueryItem(name: liveKey, value: "0")) components.queryItems = items guard let cachedURL = components.url else { throw APIError.invalidURL } var cachedRequest = request cachedRequest.url = cachedURL return cachedRequest } }