From 7d47e2371bcee2f24f4a5f1c02ff683ebc804ed0 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 4 Apr 2023 21:12:57 +0800 Subject: [PATCH] Add convenience method to get thumbnailUrl in NextcloudItemMetadataTable Signed-off-by: Claudio Cambra --- .../Database/NextcloudItemMetadataTable.swift | 14 ++++++++++++++ .../FileProviderExt/NextcloudAccount.swift | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Database/NextcloudItemMetadataTable.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Database/NextcloudItemMetadataTable.swift index 3f76da4e0..44b1ddf95 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Database/NextcloudItemMetadataTable.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Database/NextcloudItemMetadataTable.swift @@ -196,4 +196,18 @@ class NextcloudItemMetadataTable: Object { func canUnlock(as user: String) -> Bool { return !lock || (lockOwner == user && lockOwnerType == 0) } + + func thumbnailUrl(size: CGSize) -> URL? { + guard hasPreview else { + return nil + } + + let urlBase = urlBase.urlEncoded! + let webdavUrl = urlBase + NextcloudAccount.webDavFilesUrlSuffix + user // Leave the leading slash + let serverFileRelativeUrl = serverUrl.replacingOccurrences(of: webdavUrl, with: "") + "/" + fileName + + let urlString = "\(urlBase)/index.php/core/preview.png?file=\(serverFileRelativeUrl)&x=\(size.width)&y=\(size.height)&a=1&mode=cover" + + return URL(string: urlString) + } } diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/NextcloudAccount.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/NextcloudAccount.swift index a1b996385..0dc628d7d 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/NextcloudAccount.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/NextcloudAccount.swift @@ -16,7 +16,7 @@ import Foundation import FileProvider class NextcloudAccount: NSObject { - private let webDavFilesUrlSuffix: String = "/remote.php/dav/files/" + static let webDavFilesUrlSuffix: String = "/remote.php/dav/files/" let username, password, ncKitAccount, serverUrl, davFilesUrl: String init(user: String, serverUrl: String, password: String) { @@ -24,7 +24,7 @@ class NextcloudAccount: NSObject { self.password = password self.ncKitAccount = user + " " + serverUrl self.serverUrl = serverUrl - self.davFilesUrl = serverUrl + webDavFilesUrlSuffix + user + self.davFilesUrl = serverUrl + NextcloudAccount.webDavFilesUrlSuffix + user super.init() } -- 2.30.2