Skip to content

Commit

Permalink
feat: Public share archive request working
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Nov 28, 2024
1 parent 66fa72f commit 424a60c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ extension MultipleSelectionFloatingPanelViewController {

if let publicShareProxy = driveFileManager.publicShareProxy {
downloadPublicShareArchivedFiles(downloadCellPath: indexPath,
driveFileManager: driveFileManager,
publicShareProxy: publicShareProxy) { result in
switch result {
case .success(let archiveUrl):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ final class MultipleSelectionFloatingPanelViewController: UICollectionViewContro
}
}

// TODO: make it work
// TODO:  make it work
func downloadPublicShareArchivedFiles(downloadCellPath: IndexPath,
driveFileManager: DriveFileManager,
publicShareProxy: PublicShareProxy,
completion: @escaping (Result<URL, DriveError>) -> Void) {
Task { [proxyFiles = files.map { $0.proxify() }, currentProxyDirectory = currentDirectory.proxify()] in
Expand All @@ -154,8 +153,10 @@ final class MultipleSelectionFloatingPanelViewController: UICollectionViewContro
} else {
archiveBody = .init(files: proxyFiles)
}
let response = try await driveFileManager.apiFetcher.buildArchive(
drive: driveFileManager.drive,

let response = try await PublicShareApiFetcher().buildPublicShareArchive(
driveId: publicShareProxy.driveId,
linkUuid: publicShareProxy.shareLinkUid,
body: archiveBody
)
currentArchiveId = response.uuid
Expand All @@ -168,9 +169,10 @@ final class MultipleSelectionFloatingPanelViewController: UICollectionViewContro
completion(.failure(error ?? .unknownError))
}
}
DownloadQueue.instance.addToQueue(archiveId: response.uuid,
driveId: self.driveFileManager.drive.id,
userId: accountManager.currentUserId)
DownloadQueue.instance.addPublicShareArchiveToQueue(archiveId: response.uuid,
driveFileManager: driveFileManager,
publicShareProxy: publicShareProxy)

self.collectionView.reloadItems(at: [downloadCellPath])
} catch {
completion(.failure(error as? DriveError ?? .unknownError))
Expand Down
5 changes: 5 additions & 0 deletions kDriveCore/Data/Api/Endpoint+Share.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public extension Endpoint {
return shareLinkFileV2(driveId: driveId, linkUuid: linkUuid, fileId: fileId).appending(path: "/download")
}

/// Archive files from a share link
static func publicShareArchive(driveId: Int, linkUuid: String) -> Endpoint {
return shareUrlV2.appending(path: "/\(driveId)/share/\(linkUuid)/archive")
}

func showOfficeShareLinkFile(driveId: Int, linkUuid: String, fileId: Int) -> Endpoint {
return Self.shareUrlV1.appending(path: "/share/\(driveId)/\(linkUuid)/preview/text/\(fileId)")
}
Expand Down
12 changes: 12 additions & 0 deletions kDriveCore/Data/Api/PublicShareApiFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,16 @@ public extension PublicShareApiFetcher {
let shareLinkFiles: ValidServerResponse<[File]> = try await perform(request: request)
return shareLinkFiles
}

func buildPublicShareArchive(driveId: Int,
linkUuid: String,
body: ArchiveBody) async throws -> DownloadArchiveResponse {
let shareLinkArchiveUrl = Endpoint.publicShareArchive(driveId: driveId, linkUuid: linkUuid).url
let request = Session.default.request(shareLinkArchiveUrl,
method: .post,
parameters: body,
encoder: JSONParameterEncoder.convertToSnakeCase)
let archiveResponse: ValidServerResponse<DownloadArchiveResponse> = try await perform(request: request)
return archiveResponse.validApiResponse.data
}
}

0 comments on commit 424a60c

Please sign in to comment.