diff --git a/kDriveCore/Data/DownloadQueue/DownloadOperation/DownloadArchiveOperation.swift b/kDriveCore/Data/DownloadQueue/DownloadOperation/DownloadArchiveOperation.swift index 4ae283bac..ac62eec24 100644 --- a/kDriveCore/Data/DownloadQueue/DownloadOperation/DownloadArchiveOperation.swift +++ b/kDriveCore/Data/DownloadQueue/DownloadOperation/DownloadArchiveOperation.swift @@ -123,14 +123,7 @@ public class DownloadArchiveOperation: Operation { if let token { var request = URLRequest(url: url) request.setValue("Bearer \(token.accessToken)", forHTTPHeaderField: "Authorization") - task = urlSession.downloadTask(with: request, completionHandler: downloadCompletion) - progressObservation = task?.progress.observe(\.fractionCompleted, options: .new) { _, value in - guard let newValue = value.newValue else { - return - } - DownloadQueue.instance.publishProgress(newValue, for: archiveId) - } - task?.resume() + downloadRequest(request) } else { error = .localError // Other error? end(sessionUrl: url) @@ -142,6 +135,17 @@ public class DownloadArchiveOperation: Operation { } } + func downloadRequest(_ request: URLRequest) { + task = urlSession.downloadTask(with: request, completionHandler: downloadCompletion) + progressObservation = task?.progress.observe(\.fractionCompleted, options: .new) { _, value in + guard let newValue = value.newValue else { + return + } + DownloadQueue.instance.publishProgress(newValue, for: self.archiveId) + } + task?.resume() + } + func downloadCompletion(url: URL?, response: URLResponse?, error: Error?) { let statusCode = (response as? HTTPURLResponse)?.statusCode ?? -1 diff --git a/kDriveCore/Data/DownloadQueue/DownloadOperation/DownloadPublicShareArchiveOperation.swift b/kDriveCore/Data/DownloadQueue/DownloadOperation/DownloadPublicShareArchiveOperation.swift index 3bbb611a1..45ea097a1 100644 --- a/kDriveCore/Data/DownloadQueue/DownloadOperation/DownloadPublicShareArchiveOperation.swift +++ b/kDriveCore/Data/DownloadQueue/DownloadOperation/DownloadPublicShareArchiveOperation.swift @@ -55,15 +55,8 @@ public final class DownloadPublicShareArchiveOperation: DownloadArchiveOperation linkUuid: publicShareProxy.shareLinkUid, archiveUuid: archiveId ).url - let request = URLRequest(url: url) - task = urlSession.downloadTask(with: request, completionHandler: downloadCompletion) - progressObservation = task?.progress.observe(\.fractionCompleted, options: .new) { _, value in - guard let newValue = value.newValue else { - return - } - DownloadQueue.instance.publishProgress(newValue, for: self.archiveId) - } - task?.resume() + let request = URLRequest(url: url) + downloadRequest(request) } }