yattee/Model/Accounts/InstancesBridge.swift

40 lines
1.2 KiB
Swift
Raw 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,
"apiURL": value.apiURL,
"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"
return Instance(app: app, id: id, name: name, apiURL: apiURL, frontendURL: frontendURL, proxiesVideos: proxiesVideos)
2021-10-27 21:11:38 +00:00
}
}