Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions Sources/NextcloudFileProviderKit/Metadata/ItemMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,18 @@
guard hasPreview else {
return nil
}

let urlBase = urlBase.urlEncoded!
// Leave the leading slash in webdavUrl
let webdavUrl = urlBase + Account.webDavFilesUrlSuffix + user
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)
guard #available(macOS 13.0, iOS 16.0, visionOS 1.0, *) else {
return URL(
string: "\(urlBase.urlEncoded ?? "")/index.php/core/preview?fileId=\(fileId)&x=\(size.width)&y=\(size.height)&a=true"
)

Check warning on line 168 in Sources/NextcloudFileProviderKit/Metadata/ItemMetadata.swift

View check run for this annotation

Codecov / codecov/patch

Sources/NextcloudFileProviderKit/Metadata/ItemMetadata.swift#L166-L168

Added lines #L166 - L168 were not covered by tests
}
return URL(string: urlBase.urlEncoded ?? "")?
Comment thread
claucambra marked this conversation as resolved.
Comment thread
claucambra marked this conversation as resolved.
.appending(components: "index.php", "core", "preview")
.appending(queryItems: [
.init(name: "fileId", value: fileId),
.init(name: "x", value: "\(size.width)"),
.init(name: "y", value: "\(size.height)"),
Comment thread
claucambra marked this conversation as resolved.
.init(name: "a", value: "true")
])
}
}
23 changes: 23 additions & 0 deletions Tests/NextcloudFileProviderKitTests/ItemMetadataTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ItemMetadataTests.swift
// NextcloudFileProviderKit
//
// Created by Claudio Cambra on 23/5/25.
//

import Foundation
import Testing
@testable import NextcloudFileProviderKit

struct ItemMetadataTests {
@Test func thumbnailUrlCorrect() {
let account =
Account(user: "user", id: "id", serverUrl: "https://examplecloud.com", password: "bla")
var item = SendableItemMetadata(ocId: "ec-test", fileName: "test.txt", account: account)
item.fileId = "test"
item.hasPreview = true
let expectedUrl = URL(string: "https://examplecloud.com/index.php/core/preview?fileId=test&x=250.0&y=250.0&a=true")
#expect(expectedUrl != nil)
#expect(item.thumbnailUrl(size: .init(width: 250, height: 250)) == expectedUrl)
}
}