2021-10-21 03:51:50 +05:30
|
|
|
import Defaults
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct Account: Defaults.Serializable, Hashable, Identifiable {
|
|
|
|
static var bridge = AccountsBridge()
|
|
|
|
|
|
|
|
let id: String
|
2022-08-26 05:06:46 +05:30
|
|
|
var app: VideosApp?
|
2022-07-02 02:58:32 +05:30
|
|
|
let instanceID: String?
|
2022-12-12 03:45:56 +05:30
|
|
|
var name: String
|
2022-12-09 05:45:19 +05:30
|
|
|
let urlString: String
|
2022-08-26 05:06:46 +05:30
|
|
|
var username: String
|
|
|
|
var password: String?
|
2021-10-21 03:51:50 +05:30
|
|
|
let anonymous: Bool
|
2022-07-02 02:58:32 +05:30
|
|
|
let country: String?
|
|
|
|
let region: String?
|
2021-10-21 03:51:50 +05:30
|
|
|
|
2021-10-28 02:41:38 +05:30
|
|
|
init(
|
|
|
|
id: String? = nil,
|
2022-07-02 02:58:32 +05:30
|
|
|
app: VideosApp? = nil,
|
2021-10-28 02:41:38 +05:30
|
|
|
instanceID: String? = nil,
|
|
|
|
name: String? = nil,
|
2022-12-09 05:45:19 +05:30
|
|
|
urlString: String? = nil,
|
2021-11-15 04:36:01 +05:30
|
|
|
username: String? = nil,
|
|
|
|
password: String? = nil,
|
2022-07-02 02:58:32 +05:30
|
|
|
anonymous: Bool = false,
|
|
|
|
country: String? = nil,
|
|
|
|
region: String? = nil
|
2021-10-28 02:41:38 +05:30
|
|
|
) {
|
2021-10-21 03:51:50 +05:30
|
|
|
self.anonymous = anonymous
|
|
|
|
|
2022-12-09 05:45:19 +05:30
|
|
|
self.id = id ?? (anonymous ? "anonymous-\(instanceID ?? urlString ?? UUID().uuidString)" : UUID().uuidString)
|
2022-07-02 02:58:32 +05:30
|
|
|
self.instanceID = instanceID
|
2022-12-12 03:45:56 +05:30
|
|
|
self.name = name ?? ""
|
2022-12-09 05:45:19 +05:30
|
|
|
self.urlString = urlString ?? ""
|
2021-11-15 04:36:01 +05:30
|
|
|
self.username = username ?? ""
|
|
|
|
self.password = password ?? ""
|
2022-07-02 02:58:32 +05:30
|
|
|
self.country = country
|
|
|
|
self.region = region
|
2022-08-26 05:06:46 +05:30
|
|
|
self.app = app ?? instance.app
|
|
|
|
}
|
|
|
|
|
2022-12-09 05:45:19 +05:30
|
|
|
var url: URL! {
|
|
|
|
URL(string: urlString)
|
|
|
|
}
|
|
|
|
|
2022-08-26 05:06:46 +05:30
|
|
|
var token: String? {
|
|
|
|
KeychainModel.shared.getAccountKey(self, "token")
|
|
|
|
}
|
|
|
|
|
|
|
|
var credentials: (String?, String?) {
|
|
|
|
AccountsModel.getCredentials(self)
|
2021-10-21 03:51:50 +05:30
|
|
|
}
|
|
|
|
|
2021-11-13 02:16:15 +05:30
|
|
|
var instance: Instance! {
|
2023-06-08 02:07:37 +05:30
|
|
|
InstancesModel.shared.find(instanceID) ?? Instance(app: app ?? .invidious, name: urlString, apiURLString: urlString)
|
2022-07-02 02:58:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
var isPublic: Bool {
|
|
|
|
instanceID.isNil
|
2021-10-21 03:51:50 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
var description: String {
|
2022-12-12 05:48:29 +05:30
|
|
|
guard !isPublic else {
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
2023-04-22 20:44:22 +05:30
|
|
|
let (username, _) = credentials
|
|
|
|
return username ?? name
|
2021-10-21 03:51:50 +05:30
|
|
|
}
|
|
|
|
|
2022-12-12 03:45:56 +05:30
|
|
|
var urlHost: String {
|
|
|
|
URLComponents(url: url, resolvingAgainstBaseURL: false)?.host ?? ""
|
|
|
|
}
|
|
|
|
|
2021-10-21 03:51:50 +05:30
|
|
|
func hash(into hasher: inout Hasher) {
|
2021-11-15 04:36:01 +05:30
|
|
|
hasher.combine(username)
|
2021-10-21 03:51:50 +05:30
|
|
|
}
|
2022-12-10 07:31:59 +05:30
|
|
|
|
|
|
|
var feedCacheKey: String {
|
|
|
|
"feed-\(id)"
|
|
|
|
}
|
2021-10-21 03:51:50 +05:30
|
|
|
}
|