Add method to convert dictionary to NextcloudAccount
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 27 Feb 2024 14:43:58 +0000 (22:43 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 17 Apr 2024 08:38:48 +0000 (16:38 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Extensions/Logger+Extensions.swift
shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/NextcloudAccount.swift

index 0f84447e28371b2b74f945dc7487b1be90ca80e8..e9e5d78fd0d2a987c907e684063b34ae75ba205a 100644 (file)
@@ -27,6 +27,7 @@ extension Logger {
     static let localFileOps = Logger(subsystem: subsystem, category: "localfileoperations")
     static let ncFilesDatabase = Logger(subsystem: subsystem, category: "nextcloudfilesdatabase")
     static let shares = Logger(subsystem: subsystem, category: "shares")
+    static let ncAccount = Logger(subsystem: subsystem, category: "ncAccount")
     static let materialisedFileHandling = Logger(
         subsystem: subsystem, category: "materialisedfilehandling"
     )
index 14c242b49332ed3fc034a5887a0ae8079803ec6c..b522d8d0386fe19cf8c86680fbb0a358c1366a05 100644 (file)
@@ -14,6 +14,7 @@
 
 import FileProvider
 import Foundation
+import OSLog
 
 let ncAccountDictUsernameKey = "usernameKey"
 let ncAccountDictPasswordKey = "passwordKey"
@@ -33,6 +34,24 @@ struct NextcloudAccount: Equatable {
         davFilesUrl = serverUrl + NextcloudAccount.webDavFilesUrlSuffix + user
     }
 
+    init?(dictionary: Dictionary<String, String>) {
+        guard let username = dictionary[ncAccountDictUsernameKey],
+              let password = dictionary[ncAccountDictPasswordKey],
+              let ncKitAccount = dictionary[ncAccountDictNcKitAccountKey],
+              let serverUrl = dictionary[ncAccountDictServerUrlKey],
+              let davFilesUrl = dictionary[ncAccountDictDavFilesUrlKey]
+        else {
+            Logger.ncAccount.error("Could not convert dictionary to NextcloudAccount!")
+            return nil
+        }
+
+        self.username = username
+        self.password = password
+        self.ncKitAccount = ncKitAccount
+        self.serverUrl = serverUrl
+        self.davFilesUrl = davFilesUrl
+    }
+
     func dictionary() -> Dictionary<String, String> {
         return [
             ncAccountDictUsernameKey: username,