Skip to content

Commit

Permalink
feat: Download public share
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Nov 29, 2024
1 parent 424a60c commit d6beea0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
26 changes: 20 additions & 6 deletions kDriveCore/Data/DownloadQueue/DownloadArchiveOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import Alamofire
import CocoaLumberjackSwift
import FileProvider
import Foundation
Expand All @@ -29,6 +30,7 @@ public class DownloadArchiveOperation: Operation {
@LazyInjectService var appContextService: AppContextServiceable

private let archiveId: String
private let shareDrive: AbstractDrive
private let driveFileManager: DriveFileManager
private let urlSession: FileDownloadSession
private let publicShareProxy: PublicShareProxy?
Expand Down Expand Up @@ -70,10 +72,12 @@ public class DownloadArchiveOperation: Operation {
}

public init(archiveId: String,
shareDrive: AbstractDrive,
driveFileManager: DriveFileManager,
urlSession: FileDownloadSession,
publicShareProxy: PublicShareProxy? = nil) {
self.archiveId = archiveId
self.shareDrive = shareDrive
self.driveFileManager = driveFileManager
self.urlSession = urlSession
self.publicShareProxy = publicShareProxy
Expand Down Expand Up @@ -120,6 +124,22 @@ public class DownloadArchiveOperation: Operation {
"[DownloadOperation] Downloading Archive of public share files \(archiveId) with session \(urlSession.identifier)"
)

let url = Endpoint.getArchive(drive: shareDrive, uuid: 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()
}

func authenticatedDownload() {
DDLogInfo("[DownloadOperation] Downloading Archive of files \(archiveId) with session \(urlSession.identifier)")

let url = Endpoint.getArchive(drive: driveFileManager.drive, uuid: archiveId).url

if let userToken = accountManager.getTokenForUserId(driveFileManager.drive.userId) {
Expand All @@ -146,12 +166,6 @@ public class DownloadArchiveOperation: Operation {
}
}

func authenticatedDownload() {
DDLogInfo("[DownloadOperation] Downloading Archive of files \(archiveId) with session \(urlSession.identifier)")

// TODO: missing imp
}

func downloadCompletion(url: URL?, response: URLResponse?, error: Error?) {
let statusCode = (response as? HTTPURLResponse)?.statusCode ?? -1

Expand Down
3 changes: 3 additions & 0 deletions kDriveCore/Data/DownloadQueue/DownloadQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public final class DownloadQueue: ParallelismHeuristicDelegate {

let operation = DownloadArchiveOperation(
archiveId: archiveId,
shareDrive: publicShareProxy.proxyDrive,
driveFileManager: driveFileManager,
urlSession: self.bestSession,
publicShareProxy: publicShareProxy
Expand All @@ -209,6 +210,7 @@ public final class DownloadQueue: ParallelismHeuristicDelegate {
OperationQueueHelper.disableIdleTimer(false, hasOperationsInQueue: !self.operationsInQueue.isEmpty)
}
}

self.operationQueue.addOperation(operation)
self.archiveOperationsInQueue[archiveId] = operation
}
Expand All @@ -226,6 +228,7 @@ public final class DownloadQueue: ParallelismHeuristicDelegate {

let operation = DownloadArchiveOperation(
archiveId: archiveId,
shareDrive: drive,
driveFileManager: driveFileManager,
urlSession: self.bestSession
)
Expand Down
4 changes: 4 additions & 0 deletions kDriveCore/Data/Models/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ public struct PublicShareProxy {
self.fileId = fileId
self.shareLinkUid = shareLinkUid
}

public var proxyDrive: ProxyDrive {
ProxyDrive(id: driveId)
}
}

public enum SortType: String {
Expand Down

0 comments on commit d6beea0

Please sign in to comment.