2021-09-25 08:18:22 +00:00
|
|
|
import Defaults
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct Instance: Defaults.Serializable, Hashable, Identifiable {
|
|
|
|
static var bridge = InstancesBridge()
|
|
|
|
|
2021-10-20 22:21:50 +00:00
|
|
|
let app: VideosApp
|
2021-10-19 21:27:04 +00:00
|
|
|
let id: String
|
2021-09-25 08:18:22 +00:00
|
|
|
let name: String
|
2021-10-27 21:11:38 +00:00
|
|
|
let apiURL: String
|
|
|
|
var frontendURL: String?
|
2022-07-21 21:52:09 +00:00
|
|
|
var proxiesVideos: Bool
|
2021-09-25 08:18:22 +00:00
|
|
|
|
2022-07-21 21:52:09 +00:00
|
|
|
init(app: VideosApp, id: String? = nil, name: String, apiURL: String, frontendURL: String? = nil, proxiesVideos: Bool = false) {
|
2021-10-16 22:48:58 +00:00
|
|
|
self.app = app
|
2021-10-19 21:27:04 +00:00
|
|
|
self.id = id ?? UUID().uuidString
|
2021-09-25 08:18:22 +00:00
|
|
|
self.name = name
|
2021-10-27 21:11:38 +00:00
|
|
|
self.apiURL = apiURL
|
|
|
|
self.frontendURL = frontendURL
|
2022-07-21 21:52:09 +00:00
|
|
|
self.proxiesVideos = proxiesVideos
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
|
2021-10-20 22:21:50 +00:00
|
|
|
var anonymous: VideosAPI {
|
|
|
|
switch app {
|
|
|
|
case .invidious:
|
|
|
|
return InvidiousAPI(account: anonymousAccount)
|
|
|
|
case .piped:
|
|
|
|
return PipedAPI(account: anonymousAccount)
|
2022-10-26 11:11:35 +00:00
|
|
|
case .demoApp:
|
|
|
|
return DemoAppAPI()
|
2021-10-20 22:21:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
var description: String {
|
2021-10-16 22:48:58 +00:00
|
|
|
"\(app.name) - \(shortDescription)"
|
|
|
|
}
|
|
|
|
|
|
|
|
var longDescription: String {
|
2022-10-26 11:11:35 +00:00
|
|
|
guard app != .demoApp else { return "Demo" }
|
|
|
|
|
|
|
|
return name.isEmpty ? "\(app.name) - \(apiURL)" : "\(app.name) - \(name) (\(apiURL))"
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var shortDescription: String {
|
2021-10-27 21:11:38 +00:00
|
|
|
name.isEmpty ? apiURL : name
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var anonymousAccount: Account {
|
2022-09-04 15:28:30 +00:00
|
|
|
Account(instanceID: id, name: "Anonymous".localized(), url: apiURL, anonymous: true)
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
|
2021-10-26 22:59:59 +00:00
|
|
|
var urlComponents: URLComponents {
|
2021-10-27 21:11:38 +00:00
|
|
|
URLComponents(string: apiURL)!
|
2021-10-26 22:59:59 +00:00
|
|
|
}
|
|
|
|
|
2021-10-28 17:14:55 +00:00
|
|
|
var frontendHost: String? {
|
|
|
|
guard let url = app == .invidious ? apiURL : frontendURL else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return URLComponents(string: url)?.host
|
2021-10-26 22:59:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
func hash(into hasher: inout Hasher) {
|
2021-10-27 21:11:38 +00:00
|
|
|
hasher.combine(apiURL)
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
}
|