import Foundation /// Reading ipx without the page: the badge and CarPlay (#420), which has no web view. Signed in /// as the player is, by the credentials or else the cookies the web view left (CookieBridge). enum API { private static let session: URLSession = { let cfg = URLSessionConfiguration.default cfg.httpCookieStorage = .shared cfg.timeoutIntervalForRequest = 20 return URLSession(configuration: cfg) }() /// The body of a 200, or nil: not signed in, no server, no connection. static func get(_ path: String) async -> Data? { guard let url = Server.resolveForPlayer(path) else { return nil } var req = URLRequest(url: url) req.setValue("application/json", forHTTPHeaderField: "Accept") Credentials.headers.forEach { req.setValue($1, forHTTPHeaderField: $0) } guard let (data, resp) = try? await session.data(for: req), (resp as? HTTPURLResponse)?.statusCode == 200 else { return nil } return data } }