yattee/Model/Accounts/InstancesBridge.swift

40 lines
1.2 KiB
Swift
Raw Permalink Normal View History

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,
2022-12-09 00:15:19 +00:00
"apiURL": value.apiURLString,
"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"]
let proxiesVideos = object["proxiesVideos"] == "true"
2022-12-09 00:15:19 +00:00
return Instance(app: app, id: id, name: name, apiURLString: apiURL, frontendURL: frontendURL, proxiesVideos: proxiesVideos)
2021-10-27 21:11:38 +00:00
}
}