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