1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 22:30:32 +05:30
yattee/Model/Accounts/InstancesBridge.swift

40 lines
1.2 KiB
Swift
Raw Normal View History

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,
"apiURL": value.apiURL,
"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"]
let proxiesVideos = object["proxiesVideos"] == "true"
return Instance(app: app, id: id, name: name, apiURL: apiURL, frontendURL: frontendURL, proxiesVideos: proxiesVideos)
2021-10-28 02:41:38 +05:30
}
}