mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-13 13:00:40 +00:00
Merge branch 'dev'
This commit is contained in:
commit
d51f8fd5ed
1 changed files with 49 additions and 5 deletions
|
|
@ -163,12 +163,27 @@ class iCloudSyncManager {
|
|||
|
||||
do {
|
||||
if self.isValidValueType(value) {
|
||||
if value is [Any] || value is [String: Any] {
|
||||
// Validate JSON serialization
|
||||
_ = try JSONSerialization.data(withJSONObject: value)
|
||||
if let arrayValue = value as? [Any] {
|
||||
if !isValidPropertyListArray(arrayValue) {
|
||||
Logger.shared.log("Skipping key \(key): contains invalid array elements", type: "Warning")
|
||||
continue
|
||||
}
|
||||
_ = try JSONSerialization.data(withJSONObject: arrayValue)
|
||||
} else if let dictValue = value as? [String: Any] {
|
||||
if !isValidPropertyListDictionary(dictValue) {
|
||||
Logger.shared.log("Skipping key \(key): contains invalid dictionary elements", type: "Warning")
|
||||
continue
|
||||
}
|
||||
_ = try JSONSerialization.data(withJSONObject: dictValue)
|
||||
}
|
||||
|
||||
do {
|
||||
container.set(value, forKey: key)
|
||||
syncedKeys += 1
|
||||
} catch {
|
||||
Logger.shared.log("Failed to store key \(key) in iCloud: \(error.localizedDescription)", type: "Error")
|
||||
continue
|
||||
}
|
||||
container.set(value, forKey: key)
|
||||
syncedKeys += 1
|
||||
}
|
||||
} catch {
|
||||
Logger.shared.log("Failed to sync key \(key): \(error.localizedDescription)", type: "Warning")
|
||||
|
|
@ -394,4 +409,33 @@ class iCloudSyncManager {
|
|||
let docs = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
||||
return docs.appendingPathComponent("modules.json")
|
||||
}
|
||||
|
||||
private func isValidPropertyListArray(_ array: [Any]) -> Bool {
|
||||
for item in array {
|
||||
if !isValidPropertyListType(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private func isValidPropertyListDictionary(_ dict: [String: Any]) -> Bool {
|
||||
for (_, value) in dict {
|
||||
if !isValidPropertyListType(value) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private func isValidPropertyListType(_ value: Any) -> Bool {
|
||||
if value is String || value is Bool || value is Int || value is Float || value is Double || value is Data || value is Date {
|
||||
return true
|
||||
} else if let array = value as? [Any] {
|
||||
return isValidPropertyListArray(array)
|
||||
} else if let dict = value as? [String: Any] {
|
||||
return isValidPropertyListDictionary(dict)
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue