From ba685fb6014fa8f62bc20857c55c881c643be270 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 27 Feb 2024 23:53:49 +0800 Subject: [PATCH] Add method to get an item's server path through FPUIExtensionService Signed-off-by: Claudio Cambra --- .../Services/FPUIExtensionService.swift | 1 + .../Services/FPUIExtensionServiceSource.swift | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Services/FPUIExtensionService.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Services/FPUIExtensionService.swift index 4cfa0fe4d..b308fae05 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Services/FPUIExtensionService.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Services/FPUIExtensionService.swift @@ -15,4 +15,5 @@ let fpUiExtensionServiceName = NSFileProviderServiceName( @objc protocol FPUIExtensionService { func shares(forItemIdentifier itemIdentifier: NSFileProviderItemIdentifier) async -> [NKShare]? func credentials() async -> NSDictionary + func itemServerPath(identifier: NSFileProviderItemIdentifier) async -> NSString? } diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Services/FPUIExtensionServiceSource.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Services/FPUIExtensionServiceSource.swift index af4c39a90..7e58a0e01 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Services/FPUIExtensionServiceSource.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Services/FPUIExtensionServiceSource.swift @@ -51,4 +51,23 @@ class FPUIExtensionServiceSource: NSObject, NSFileProviderServiceSource, NSXPCLi func credentials() async -> NSDictionary { return (fpExtension.ncAccount?.dictionary() ?? [:]) as NSDictionary } + + func itemServerPath(identifier: NSFileProviderItemIdentifier) async -> NSString? { + let rawIdentifier = identifier.rawValue + Logger.shares.info("Fetching shares for item \(rawIdentifier, privacy: .public)") + + guard let baseUrl = fpExtension.ncAccount?.davFilesUrl else { + Logger.shares.error("Could not fetch shares as ncAccount on parent extension is nil") + return nil + } + + let dbManager = NextcloudFilesDatabaseManager.shared + guard let item = dbManager.itemMetadataFromFileProviderItemIdentifier(identifier) else { + Logger.shares.error("No item \(rawIdentifier, privacy: .public) in db, no shares.") + return nil + } + + let completePath = item.serverUrl + "/" + item.fileName + return completePath.replacingOccurrences(of: baseUrl, with: "") as NSString + } } -- 2.30.2