fix(file-provider): Remove unused thumbnail wrapper

Signed-off-by: Claudio Cambra <[email protected]>
Assisted-by: Codex:GPT-6
Signed-off-by: Claudio Cambra <[email protected]>
This commit is contained in:
Claudio Cambra committed 2026-11-06 00:54:12 +08:00
1 parent d0f7b0d261
commit 0a93f41a98
2 files changed
+26 -15

No files matched your search

@@ -386,12 +386,6 @@ public extension Item {
return (localPath, fpItem, nil)
}
func fetchThumbnail(size: CGSize, domain: NSFileProviderDomain? = nil, progress: Progress = .init()) async -> (Data?, Error?) {
await NetworkOperationCancellation(log: logger.log).run(progress: progress) { @Sendable cancellation in
await self.performFetchThumbnail(size: size, domain: domain, progress: progress, cancellation: cancellation)
}
}
internal func performFetchThumbnail(
size: CGSize,
domain: NSFileProviderDomain?,
@@ -1115,27 +1115,38 @@ final class ItemFetchTests: NextcloudFileProviderKitTestCase {
func testCancellingThumbnailCancelsNetworkTask() async throws {
let (item, remoteInterface, _) = makeFetchItem(preview: true)
let progress = Progress()
let session = URLSession(configuration: .ephemeral)
defer { session.invalidateAndCancel() }
let (networkTask, networkCompletion) = try observedNetworkTask(
in: session,
url: XCTUnwrap(URL(string: "https://example.invalid/preview"))
)
let (started, continuation) = AsyncStream<Void>.makeStream()
defer { continuation.finish() }
remoteInterface.thumbnailHandler = { _, taskHandler in
taskHandler(networkTask)
progress.cancel()
continuation.yield(())
let cancelled = await waitForCancellation()
XCTAssertTrue(cancelled, "Cancellation did not reach the operation.")
}
let batch = makeThumbnailBatch(identifiers: [item.itemIdentifier], remoteInterface: remoteInterface)
defer { batch.progress.cancel() }
let startedValue = try await nextTestValue(from: started)
_ = try XCTUnwrap(startedValue)
batch.progress.cancel()
let (data, error) = await item.fetchThumbnail(size: CGSize(width: 32, height: 32), progress: progress)
XCTAssertNil(data)
XCTAssertEqual((error as? CocoaError)?.code, .userCancelled)
let thumbnailValue = try await nextTestValue(from: batch.thumbnails)
let thumbnail = try XCTUnwrap(thumbnailValue)
XCTAssertEqual(thumbnail.identifier, item.itemIdentifier)
XCTAssertNil(thumbnail.data)
XCTAssertEqual((thumbnail.error as? CocoaError)?.code, .userCancelled)
let nextThumbnail = try await nextTestValue(from: batch.thumbnails)
XCTAssertNil(nextThumbnail)
let completion = try await nextTestValue(from: batch.completion)
XCTAssertEqual((completion.flatMap(\.self) as? CocoaError)?.code, .userCancelled)
let networkError = try await nextTestValue(from: networkCompletion)
XCTAssertEqual(networkError, NSURLErrorCancelled)
XCTAssertNil(progress.cancellationHandler)
XCTAssertNil(batch.progress.cancellationHandler)
}
func testCancelledProgressDoesNotStartThumbnailDownload() async {
@@ -1144,7 +1155,10 @@ final class ItemFetchTests: NextcloudFileProviderKitTestCase {
progress.cancel()
remoteInterface.thumbnailHandler = { _, _ in XCTFail("Cancelled thumbnail must not start a transfer") }
let (data, error) = await item.fetchThumbnail(size: CGSize(width: 32, height: 32), progress: progress)
let (data, error) = await item.performFetchThumbnail(
size: CGSize(width: 32, height: 32), domain: nil, progress: progress,
cancellation: NetworkOperationCancellation(log: FileProviderLogMock())
)
XCTAssertNil(data)
XCTAssertEqual((error as? CocoaError)?.code, .userCancelled)
@@ -1156,7 +1170,10 @@ final class ItemFetchTests: NextcloudFileProviderKitTestCase {
remoteInterface.thumbnailData = Data("Late thumbnail response".utf8)
remoteInterface.thumbnailCompletionHandler = { progress.cancel() }
let (data, error) = await item.fetchThumbnail(size: CGSize(width: 32, height: 32), progress: progress)
let (data, error) = await item.performFetchThumbnail(
size: CGSize(width: 32, height: 32), domain: nil, progress: progress,
cancellation: NetworkOperationCancellation(log: FileProviderLogMock())
)
XCTAssertNil(data)
XCTAssertEqual((error as? CocoaError)?.code, .userCancelled)