1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50: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,
2022-12-09 05:45:19 +05:30
"apiURL": value.apiURLString,
"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"
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
}
}