Export profiles to separate JSONs
Use id as contextual filename.
This commit is contained in:
parent
2aae3499de
commit
2d2884fdea
|
@ -53,6 +53,7 @@ extension ConnectionService {
|
|||
try migrateToBaseConfiguration(&json)
|
||||
try migrateToBuildNumber(&json)
|
||||
try migrateHostProfileConfigurations()
|
||||
try migrateSplitProfileSerialization(&json)
|
||||
}
|
||||
|
||||
return try JSONSerialization.data(withJSONObject: json, options: [])
|
||||
|
@ -125,6 +126,42 @@ extension ConnectionService {
|
|||
}
|
||||
}
|
||||
|
||||
static func migrateSplitProfileSerialization(_ json: inout [String: Any]) throws {
|
||||
guard let profiles = json["profiles"] as? [[String: Any]] else {
|
||||
return
|
||||
}
|
||||
|
||||
let fm = FileManager.default
|
||||
let providersParentURL = fm.userURL(for: .documentDirectory, appending: AppConstants.Store.providersDirectory)
|
||||
let hostsParentURL = fm.userURL(for: .documentDirectory, appending: AppConstants.Store.hostsDirectory)
|
||||
try? fm.createDirectory(at: providersParentURL, withIntermediateDirectories: false, attributes: nil)
|
||||
try? fm.createDirectory(at: hostsParentURL, withIntermediateDirectories: false, attributes: nil)
|
||||
|
||||
for p in profiles {
|
||||
if var provider = p["provider"] as? [String: Any] {
|
||||
guard let id = provider["name"] as? String else {
|
||||
continue
|
||||
}
|
||||
// provider["id"] = id
|
||||
// provider.removeValue(forKey: "name")
|
||||
|
||||
let url = providersParentURL.appendingPathComponent("\(id).json")
|
||||
let data = try JSONSerialization.data(withJSONObject: provider, options: [])
|
||||
try data.write(to: url)
|
||||
} else if var host = p["host"] as? [String: Any] {
|
||||
guard let id = host["title"] as? String else {
|
||||
continue
|
||||
}
|
||||
// host["id"] = id
|
||||
// host.removeValue(forKey: "title")
|
||||
|
||||
let url = hostsParentURL.appendingPathComponent("\(id).json")
|
||||
let data = try JSONSerialization.data(withJSONObject: host, options: [])
|
||||
try data.write(to: url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Helpers
|
||||
|
||||
private static func migrateSessionConfiguration(in map: inout [String: Any]) {
|
||||
|
|
Loading…
Reference in New Issue