2021-10-28 02:41:38 +05:30
|
|
|
import Defaults
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct InstancesBridge: Defaults.Bridge {
|
|
|
|
typealias Value = Instance
|
|
|
|
typealias Serializable = [String: String]
|
|
|
|
|
|
|
|
func serialize(_ value: Value?) -> Serializable? {
|
2022-09-28 19:57:01 +05:30
|
|
|
guard let value else {
|
2021-10-28 02:41:38 +05:30
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
"app": value.app.rawValue,
|
|
|
|
"id": value.id,
|
|
|
|
"name": value.name,
|
2022-12-09 05:45:19 +05:30
|
|
|
"apiURL": value.apiURLString,
|
2022-07-22 03:22:09 +05:30
|
|
|
"frontendURL": value.frontendURL ?? "",
|
|
|
|
"proxiesVideos": value.proxiesVideos ? "true" : "false"
|
2021-10-28 02:41:38 +05:30
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
func deserialize(_ object: Serializable?) -> Value? {
|
|
|
|
guard
|
2022-09-28 19:57:01 +05:30
|
|
|
let object,
|
2021-10-28 02:41:38 +05:30
|
|
|
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-22 03:22:09 +05:30
|
|
|
let proxiesVideos = object["proxiesVideos"] == "true"
|
|
|
|
|
2022-12-09 05:45:19 +05:30
|
|
|
return Instance(app: app, id: id, name: name, apiURLString: apiURL, frontendURL: frontendURL, proxiesVideos: proxiesVideos)
|
2021-10-28 02:41:38 +05:30
|
|
|
}
|
|
|
|
}
|