diff --git a/Sources/NextcloudKit/NKCommon.swift b/Sources/NextcloudKit/NKCommon.swift index 0b51b1b8..73a2c71c 100644 --- a/Sources/NextcloudKit/NKCommon.swift +++ b/Sources/NextcloudKit/NKCommon.swift @@ -18,6 +18,8 @@ public protocol NextcloudKitDelegate: AnyObject, Sendable { func networkReachabilityObserver(_ typeReachability: NKCommon.TypeReachability) + func request(_ request: DataRequest, didParseResponse response: AFDataResponse) + func downloadProgress(_ progress: Float, totalBytes: Int64, totalBytesExpected: Int64, fileName: String, serverUrl: String, session: URLSession, task: URLSessionTask) func uploadProgress(_ progress: Float, totalBytes: Int64, totalBytesExpected: Int64, fileName: String, serverUrl: String, session: URLSession, task: URLSessionTask) @@ -27,6 +29,23 @@ public protocol NextcloudKitDelegate: AnyObject, Sendable { func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: Date?, size: Int64, task: URLSessionTask, error: NKError) } +public extension NextcloudKitDelegate { + func authenticationChallenge(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { } + func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) { } + + func networkReachabilityObserver(_ typeReachability: NKCommon.TypeReachability) { } + + func request(_ request: DataRequest, didParseResponse response: AFDataResponse) { } + + func downloadProgress(_ progress: Float, totalBytes: Int64, totalBytesExpected: Int64, fileName: String, serverUrl: String, session: URLSession, task: URLSessionTask) { } + func uploadProgress(_ progress: Float, totalBytes: Int64, totalBytesExpected: Int64, fileName: String, serverUrl: String, session: URLSession, task: URLSessionTask) { } + + func downloadingFinish(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) { } + + func downloadComplete(fileName: String, serverUrl: String, etag: String?, date: Date?, dateLastModified: Date?, length: Int64, task: URLSessionTask, error: NKError) { } + func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: Date?, size: Int64, task: URLSessionTask, error: NKError) { } +} + public struct NKCommon: Sendable { public var nksessions = ThreadSafeArray() public var delegate: NextcloudKitDelegate? diff --git a/Sources/NextcloudKit/NKMonitor.swift b/Sources/NextcloudKit/NKMonitor.swift index 8e83e13c..a0575297 100644 --- a/Sources/NextcloudKit/NKMonitor.swift +++ b/Sources/NextcloudKit/NKMonitor.swift @@ -26,6 +26,8 @@ final class NKMonitor: EventMonitor, Sendable { } func request(_ request: DataRequest, didParseResponse response: AFDataResponse) { + nkCommonInstance.delegate?.request(request, didParseResponse: response) + if let statusCode = response.response?.statusCode { //