Files
QueueCube/ios/QueueCube/Backend/Server.swift
T
buzzert 8723955705 ios: add share extension to queue and play video links
Embed an iOS and Catalyst share extension using existing discovery and player APIs. Share saved players through an App Group snapshot, preserve the queue, and verify advancing playback before reporting success.

Cover URL provider transport, settings migration, discovery addresses, duplicate handling, cancellation, and partial enqueue/play outcomes with focused tests. Document authentication and signing limits.
2026-10-20 22:08:12 -07:00

71 lines
1.7 KiB
Swift

//
// Server.swift
// QueueCube
//
// Created by James Magahern on 6/10/25.
//
import Foundation
import Network
struct Server: Identifiable, Codable, Equatable
{
let serviceName: String?
let baseURL: URL
var id: String { baseURL.absoluteString }
var api: API { API(baseURL: baseURL) }
var displayName: String {
if let serviceName {
return serviceName.queueCubeServiceName
}
let components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)!
return components.host ?? baseURL.absoluteString
}
init?(serviceName: String?, host: String, port: UInt16) {
self.serviceName = serviceName
// Network.framework can append an interface to IPv4 and IPv6 addresses.
// URL hosts only support that scope on IPv6 literals.
var host = host
if let scope = host.firstIndex(of: "%"),
IPv4Address(String(host[..<scope])) != nil {
host = String(host[..<scope])
}
if host.contains(":") {
if !host.hasPrefix("[") { host = "[\(host)]" }
}
var components = URLComponents()
components.scheme = "http"
components.host = host
components.port = Int(port)
components.path = "/api"
guard let url = components.url else {
return nil
}
self.baseURL = url
}
init(baseURL: URL) {
self.serviceName = nil
self.baseURL = baseURL
}
}
extension String
{
var queueCubeServiceName: String {
let regex = /.* \((.*)\)/
if let match = try? regex.firstMatch(in: self) {
return String(match.output.1)
}
return self
}
}