feat: consolidate iOS with API and web preserving history
Rebuild & Deploy / rebuild (push) Failing after 23s
Rebuild & Deploy / rebuild (push) Failing after 23s
This commit is contained in:
commit
d735ee72fa
102 files changed
+13077
-258
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import Foundation
|
||||
|
||||
struct ServerConfig: Equatable {
|
||||
let baseURL: URL
|
||||
let livekitURL: URL
|
||||
|
||||
enum ConfigError: LocalizedError, Equatable {
|
||||
case notHTTPS(String)
|
||||
case invalidURL(String)
|
||||
|
||||
var errorDescription: String? {
|
||||
switch self {
|
||||
case .notHTTPS(let raw):
|
||||
return "Server URL must use https: \(raw)"
|
||||
case .invalidURL(let raw):
|
||||
return "Invalid server URL: \(raw)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static func parse(_ raw: String) -> Result<ServerConfig, ConfigError> {
|
||||
let trimmed = raw.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else { return .failure(.invalidURL(raw)) }
|
||||
var candidate = trimmed
|
||||
if !candidate.contains("://") { candidate = "https://" + candidate }
|
||||
guard let components = URLComponents(string: candidate),
|
||||
let scheme = components.scheme?.lowercased(),
|
||||
let host = components.host, !host.isEmpty else {
|
||||
return .failure(.invalidURL(raw))
|
||||
}
|
||||
if scheme != "https" { return .failure(.notHTTPS(raw)) }
|
||||
guard components.user == nil, components.password == nil,
|
||||
components.query == nil, components.fragment == nil else {
|
||||
return .failure(.invalidURL(raw))
|
||||
}
|
||||
var c = components
|
||||
c.scheme = "https"
|
||||
c.host = host.lowercased()
|
||||
if c.port == 443 { c.port = nil }
|
||||
c.path = ""
|
||||
guard let base = c.url else { return .failure(.invalidURL(raw)) }
|
||||
c.scheme = "wss"
|
||||
c.path = "/livekit"
|
||||
guard let livekit = c.url else { return .failure(.invalidURL(raw)) }
|
||||
return .success(ServerConfig(baseURL: base, livekitURL: livekit))
|
||||
}
|
||||
|
||||
static func isPrivateIP(_ host: String) -> Bool {
|
||||
let parts = host.split(separator: ".").compactMap { UInt8($0) }
|
||||
guard parts.count == 4 else { return false }
|
||||
return parts[0] == 10
|
||||
|| (parts[0] == 172 && (16...31).contains(parts[1]))
|
||||
|| (parts[0] == 192 && parts[1] == 168)
|
||||
}
|
||||
|
||||
var host: String { baseURL.host ?? "" }
|
||||
}
|
||||
Reference in new issue
Block a user