2021-10-27 21:11:38 +00:00
|
|
|
import Defaults
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct InstancesBridge: Defaults.Bridge {
|
|
|
|
typealias Value = Instance
|
|
|
|
typealias Serializable = [String: String]
|
|
|
|
|
|
|
|
func serialize(_ value: Value?) -> Serializable? {
|
2022-09-28 14:27:01 +00:00
|
|
|
guard let value else {
|
2021-10-27 21:11:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
"app": value.app.rawValue,
|
|
|
|
"id": value.id,
|
|
|
|
"name": value.name,
|
|
|
|
"apiURL": value.apiURL,
|
2022-07-21 21:52:09 +00:00
|
|
|
"frontendURL": value.frontendURL ?? "",
|
|
|
|
"proxiesVideos": value.proxiesVideos ? "true" : "false"
|
2021-10-27 21:11:38 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
func deserialize(_ object: Serializable?) -> Value? {
|
|
|
|
guard
|
2022-09-28 14:27:01 +00:00
|
|
|
let object,
|
2021-10-27 21:11:38 +00:00
|
|
|
let app = VideosApp(rawValue: object["app"] ?? ""),
|
|
|
|
let id = object["id"],
|
|
|
|
let apiURL = object["apiURL"]
|
|
|
|
else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
let name = object["name"] ?? ""
|
|
|
|
let frontendURL: String? = object["frontendURL"]!.isEmpty ? nil : object["frontendURL"]
|
2022-07-21 21:52:09 +00:00
|
|
|
let proxiesVideos = object["proxiesVideos"] == "true"
|
|
|
|
|
|
|
|
return Instance(app: app, id: id, name: name, apiURL: apiURL, frontendURL: frontendURL, proxiesVideos: proxiesVideos)
|
2021-10-27 21:11:38 +00:00
|
|
|
}
|
|
|
|
}
|