Complete FileProviderEnumerator init, get correct serverUrl for enumerator item identifier

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-01-10 20:25:26 +01:00
parent fa7e441d81
commit 9f6c2df4e3
No known key found for this signature in database
GPG key ID: C839200C384636B0
2 changed files with 18 additions and 2 deletions

View file

@ -18,9 +18,25 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
private let enumeratedItemIdentifier: NSFileProviderItemIdentifier private let enumeratedItemIdentifier: NSFileProviderItemIdentifier
private let anchor = NSFileProviderSyncAnchor("an anchor".data(using: .utf8)!) private let anchor = NSFileProviderSyncAnchor("an anchor".data(using: .utf8)!)
let ncAccount: NextcloudAccount
var serverUrl: URL?
init(enumeratedItemIdentifier: NSFileProviderItemIdentifier) { init(enumeratedItemIdentifier: NSFileProviderItemIdentifier, ncAccount: NextcloudAccount) {
self.enumeratedItemIdentifier = enumeratedItemIdentifier self.enumeratedItemIdentifier = enumeratedItemIdentifier
self.ncAccount = ncAccount
if enumeratedItemIdentifier == .rootContainer {
self.serverUrl = ncAccount.serverUrl
} else {
let dbManager = NextcloudFilesDatabaseManager.shared
if let itemMetadata = dbManager.fileMetadataFromFileProviderItemIdentifier(enumeratedItemIdentifier),
let itemDirectoryMetadata = dbManager.directoryMetadataForFile(itemMetadata) {
self.serverUrl = URL(string: itemDirectoryMetadata.serverUrl + "/" + itemMetadata.fileName)
}
}
super.init() super.init()
} }

View file

@ -101,7 +101,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension {
} }
func enumerator(for containerItemIdentifier: NSFileProviderItemIdentifier, request: NSFileProviderRequest) throws -> NSFileProviderEnumerator { func enumerator(for containerItemIdentifier: NSFileProviderItemIdentifier, request: NSFileProviderRequest) throws -> NSFileProviderEnumerator {
return FileProviderEnumerator(enumeratedItemIdentifier: containerItemIdentifier) return FileProviderEnumerator(enumeratedItemIdentifier: containerItemIdentifier, ncAccount: ncAccount)
} }
// MARK: Nextcloud desktop client communication // MARK: Nextcloud desktop client communication