Skip to content

Commit

Permalink
Adapt to new return signatures upstream
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <developer@claudiocambra.com>
  • Loading branch information
claucambra committed Dec 3, 2024
1 parent 713f8cd commit 90845e3
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ extension NextcloudKit: RemoteInterface {
account: account.ncKitAccount,
options: options,
taskHandler: taskHandler
) { account, ocId, date, error in
continuation.resume(returning: (account, ocId, date, error))
) { account, ocId, date, _, error in
continuation.resume(returning: (account, ocId, date as NSDate?, error))
}
}
}
Expand All @@ -57,7 +57,7 @@ extension NextcloudKit: RemoteInterface {
etag: String?,
date: NSDate?,
size: Int64,
allHeaderFields: [AnyHashable : Any]?,
response: HTTPURLResponse?,
afError: AFError?,
remoteError: NKError
) {
Expand All @@ -72,14 +72,14 @@ extension NextcloudKit: RemoteInterface {
requestHandler: requestHandler,
taskHandler: taskHandler,
progressHandler: progressHandler
) { account, ocId, etag, date, size, allHeaderFields, afError, nkError in
) { account, ocId, etag, date, size, response, afError, nkError in
continuation.resume(returning: (
account,
ocId,
etag,
date,
date as NSDate?,
size,
allHeaderFields,
response?.response,
afError,
nkError
))
Expand All @@ -93,7 +93,7 @@ extension NextcloudKit: RemoteInterface {
overwrite: Bool,
options: NKRequestOptions,
taskHandler: @escaping (URLSessionTask) -> Void
) async -> (account: String, error: NKError) {
) async -> (account: String, data: Data?, error: NKError) {
return await withCheckedContinuation { continuation in
moveFileOrFolder(
serverUrlFileNameSource: remotePathSource,
Expand All @@ -102,8 +102,8 @@ extension NextcloudKit: RemoteInterface {
account: account.ncKitAccount,
options: options,
taskHandler: taskHandler
) { account, error in
continuation.resume(returning: (account, error))
) { account, data, error in
continuation.resume(returning: (account, data?.data, error))
}
}
}
Expand All @@ -120,7 +120,7 @@ extension NextcloudKit: RemoteInterface {
etag: String?,
date: NSDate?,
length: Int64,
allHeaderFields: [AnyHashable : Any]?,
response: HTTPURLResponse?,
afError: AFError?,
remoteError: NKError
) {
Expand All @@ -133,13 +133,13 @@ extension NextcloudKit: RemoteInterface {
requestHandler: requestHandler,
taskHandler: taskHandler,
progressHandler: progressHandler
) { account, etag, date, length, allHeaderFields, afError, remoteError in
) { account, etag, date, length, data, afError, remoteError in
continuation.resume(returning: (
account,
etag,
date,
date as NSDate?,
length,
allHeaderFields,
data?.response,
afError,
remoteError
))
Expand Down Expand Up @@ -169,7 +169,7 @@ extension NextcloudKit: RemoteInterface {
options: options,
taskHandler: taskHandler
) { account, files, data, error in
continuation.resume(returning: (account, files, data, error))
continuation.resume(returning: (account, files ?? [], data?.data, error))
}
}
}
Expand All @@ -178,10 +178,12 @@ extension NextcloudKit: RemoteInterface {
remotePath: String,
options: NKRequestOptions = .init(),
taskHandler: @escaping (URLSessionTask) -> Void = { _ in }
) async -> (account: String, error: NKError) {
) async -> (account: String, response: HTTPURLResponse?, error: NKError) {
return await withCheckedContinuation { continuation in
deleteFileOrFolder(serverUrlFileName: remotePath) { account, error in
continuation.resume(returning: (account, error))
deleteFileOrFolder(
serverUrlFileName: remotePath, account: account.ncKitAccount
) { account, response, error in
continuation.resume(returning: (account, response?.response, error))
}
}
}
Expand All @@ -203,8 +205,8 @@ extension NextcloudKit: RemoteInterface {
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in }
) async -> (account: String, data: Data?, error: NKError) {
return await withCheckedContinuation { continuation in
getCapabilities(options: options, taskHandler: taskHandler) { account, data, error in
continuation.resume(returning: (account, data, error))
getCapabilities(account: account.ncKitAccount, options: options, taskHandler: taskHandler) { account, data, error in
continuation.resume(returning: (account, data?.data, error))
}
}
}
Expand All @@ -217,7 +219,7 @@ extension NextcloudKit: RemoteInterface {
getUserProfile(
account: account.ncKitAccount, options: options, taskHandler: taskHandler
) { account, userProfile, data, error in
continuation.resume(returning: (account, userProfile, data, error))
continuation.resume(returning: (account, userProfile, data?.data, error))
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/NextcloudFileProviderKit/Interface/RemoteInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public protocol RemoteInterface {
etag: String?,
date: NSDate?,
size: Int64,
allHeaderFields: [AnyHashable: Any]?,
afError: AFError?,
response: HTTPURLResponse?,
afError: AFError?,
remoteError: NKError
)

Expand All @@ -58,7 +58,7 @@ public protocol RemoteInterface {
overwrite: Bool,
options: NKRequestOptions,
taskHandler: @escaping (_ task: URLSessionTask) -> Void
) async -> (account: String, error: NKError)
) async -> (account: String, data: Data?, error: NKError)

func download(
remotePath: String,
Expand All @@ -72,7 +72,7 @@ public protocol RemoteInterface {
etag: String?,
date: NSDate?,
length: Int64,
allHeaderFields: [AnyHashable: Any]?,
response: HTTPURLResponse?,
afError: AFError?,
remoteError: NKError
)
Expand All @@ -91,7 +91,7 @@ public protocol RemoteInterface {
remotePath: String,
options: NKRequestOptions,
taskHandler: @escaping (_ task: URLSessionTask) -> Void
) async -> (account: String, error: NKError)
) async -> (account: String, response: HTTPURLResponse?, error: NKError)

func downloadThumbnail(
url: URL,
Expand Down
2 changes: 1 addition & 1 deletion Sources/NextcloudFileProviderKit/Item/Item+Delete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public extension Item {
}
let ocId = itemIdentifier.rawValue

let (_, error) = await remoteInterface.delete(
let (_, _, error) = await remoteInterface.delete(
remotePath: serverFileNameUrl, options: .init(), taskHandler: { task in
if let domain {
NSFileProviderManager(for: domain)?.register(
Expand Down
4 changes: 2 additions & 2 deletions Sources/NextcloudFileProviderKit/Item/Item+Modify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public extension Item {
let ocId = itemIdentifier.rawValue
let isFolder = contentType.conforms(to: .directory)
let oldRemotePath = metadata.serverUrl + "/" + metadata.fileName
let (_, moveError) = await remoteInterface.move(
let (_, _, moveError) = await remoteInterface.move(
remotePathSource: oldRemotePath,
remotePathDestination: newRemotePath,
overwrite: false,
Expand Down Expand Up @@ -420,7 +420,7 @@ public extension Item {
let staleItemMetadata = staleItem.value
guard dbManager.itemMetadataFromOcId(staleItemMetadata.ocId) != nil else { continue }

let (_, deleteError) = await remoteInterface.delete(
let (_, _, deleteError) = await remoteInterface.delete(
remotePath: staleItem.key, options: .init(), taskHandler: { task in
if let domain {
NSFileProviderManager(for: domain)?.register(
Expand Down
17 changes: 9 additions & 8 deletions Tests/Interface/MockRemoteInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public class MockRemoteInterface: RemoteInterface {
etag: String?,
date: NSDate?,
size: Int64,
allHeaderFields: [AnyHashable : Any]?,
response: HTTPURLResponse?,
afError: AFError?,
remoteError: NKError
) {
Expand Down Expand Up @@ -213,12 +213,12 @@ public class MockRemoteInterface: RemoteInterface {
overwrite: Bool = false,
options: NKRequestOptions = .init(),
taskHandler: @escaping (URLSessionTask) -> Void = { _ in }
) async -> (account: String, error: NKError) {
) async -> (account: String, data: Data?, error: NKError) {
guard let itemNewName = try? name(from: remotePathDestination),
let sourceItem = item(remotePath: remotePathSource),
let destinationParent = parentItem(path: remotePathDestination),
(overwrite || !destinationParent.children.contains(where: { $0.name == itemNewName }))
else { return (accountString, .urlError) }
else { return (accountString, nil, .urlError) }

sourceItem.name = itemNewName
sourceItem.parent?.children.removeAll(where: { $0.identifier == sourceItem.identifier })
Expand All @@ -244,7 +244,7 @@ public class MockRemoteInterface: RemoteInterface {
children = nextChildren
}

return (accountString, .success)
return (accountString, nil, .success)
}

public func download(
Expand All @@ -259,7 +259,7 @@ public class MockRemoteInterface: RemoteInterface {
etag: String?,
date: NSDate?,
length: Int64,
allHeaderFields: [AnyHashable : Any]?,
response: HTTPURLResponse?,
afError: AFError?,
remoteError: NKError
) {
Expand Down Expand Up @@ -330,15 +330,16 @@ public class MockRemoteInterface: RemoteInterface {
remotePath: String,
options: NKRequestOptions = .init(),
taskHandler: @escaping (URLSessionTask) -> Void = { _ in }
) async -> (account: String, error: NKError) {
) async -> (account: String, response: HTTPURLResponse?, error: NKError) {
guard let item = item(remotePath: remotePath) else {
return (accountString, .urlError)
return (accountString, nil, .urlError)
}

item.children = []
item.parent?.children.removeAll(where: { $0.identifier == item.identifier })
item.parent = nil
return (accountString, .success)

return (accountString, nil, .success)
}

public func downloadThumbnail(
Expand Down
2 changes: 1 addition & 1 deletion Tests/Interface/MockRemoteItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MockRemoteItem: Equatable {
let file = NKFile()
file.fileName = name
file.size = size
file.date = creationDate as NSDate
file.date = creationDate
file.directory = directory
file.etag = versionIdentifier
file.ocId = identifier
Expand Down
2 changes: 1 addition & 1 deletion Tests/InterfaceTests/MockRemoteInterfaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
let expectedRoot = remoteInterface.rootItem
XCTAssertEqual(targetRootFile?.ocId, expectedRoot?.identifier)
XCTAssertEqual(targetRootFile?.fileName, expectedRoot?.name)
XCTAssertEqual(targetRootFile?.date, expectedRoot?.creationDate as? NSDate)
XCTAssertEqual(targetRootFile?.date, expectedRoot?.creationDate)
XCTAssertEqual(targetRootFile?.etag, expectedRoot?.versionIdentifier)

let resultChildren = await remoteInterface.enumerate(
Expand Down

0 comments on commit 90845e3

Please sign in to comment.