diff --git a/kDrive/AppRouter.swift b/kDrive/AppRouter.swift index cb20f8024..483edd31e 100644 --- a/kDrive/AppRouter.swift +++ b/kDrive/AppRouter.swift @@ -632,6 +632,9 @@ public struct AppRouter: AppNavigable { rootViewController.dismiss(animated: false) { guard !frozenRootFolder.isDisabled else { let noDriveViewController = NoDriveUpsaleViewController() + noDriveViewController.dismissCallback = { + rootViewController.dismiss(animated: false) {} + } let floatingPanel = UpsaleFloatingPanelController(upsaleViewController: noDriveViewController) rootViewController.present(floatingPanel, animated: true, completion: nil) return diff --git a/kDrive/UI/Controller/Files/File List/FileListViewController.swift b/kDrive/UI/Controller/Files/File List/FileListViewController.swift index b9abc2288..9c01ca9f2 100644 --- a/kDrive/UI/Controller/Files/File List/FileListViewController.swift +++ b/kDrive/UI/Controller/Files/File List/FileListViewController.swift @@ -296,8 +296,28 @@ class FileListViewController: UICollectionViewController, SwipeActionCollectionV } guard accountManager.currentAccount != nil else { + #if !ISEXTENSION + let upsaleViewController = UpsaleViewController() + + // Create an account + upsaleViewController.freeTrialCallback = { [weak self] in + self?.dismiss(animated: true) + // TODO: Present login +// MatomoUtils.track(eventWithCategory: .account, name: "openCreationWebview") +// present(RegisterViewController.instantiateInNavigationController(delegate: self), animated: true) + } + // Let the user login with the onboarding + upsaleViewController.loginCallback = { [weak self] in + self?.dismiss(animated: true) + } + + let floatingPanel = UpsaleFloatingPanelController(upsaleViewController: upsaleViewController) + present(floatingPanel, animated: true, completion: nil) + #else dismiss(animated: true) + #endif + return } diff --git a/kDrive/UI/Controller/Files/Save File/SaveFileViewController+FooterButtonDelegate.swift b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+FooterButtonDelegate.swift index d725801c0..944b44daa 100644 --- a/kDrive/UI/Controller/Files/Save File/SaveFileViewController+FooterButtonDelegate.swift +++ b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+FooterButtonDelegate.swift @@ -38,10 +38,10 @@ extension SaveFileViewController: FooterButtonDelegate { if let publicShareProxy { Task { - await savePublicShareToDrive(sourceDriveId: publicShareProxy.driveId, - destinationDriveId: drive.accountId, - fileIds: publicShareFileIds, - exceptIds: publicShareExceptIds) + try await savePublicShareToDrive(sourceDriveId: publicShareProxy.driveId, + destinationDriveId: drive.accountId, + fileIds: publicShareFileIds, + exceptIds: publicShareExceptIds) } } else { guard !items.isEmpty else { @@ -63,11 +63,14 @@ extension SaveFileViewController: FooterButtonDelegate { dismiss(animated: true) } - try? await PublicShareApiFetcher().importShareLinkFiles(sourceDriveId: sourceDriveId, - destinationDriveId: destinationDriveId, - fileIds: fileIds, - exceptIds: exceptIds) - print("savePublicShareToDrive") + guard let currentDriveFileManager = accountManager.currentDriveFileManager else { + return + } + + try await currentDriveFileManager.apiFetcher.importShareLinkFiles(sourceDriveId: sourceDriveId, + destinationDriveId: destinationDriveId, + fileIds: fileIds, + exceptIds: exceptIds) } private func saveAndDismiss(files: [ImportedFile], directory: File, drive: Drive) async { diff --git a/kDrive/UI/View/Upsale/NoDriveUpsaleViewController.swift b/kDrive/UI/View/Upsale/NoDriveUpsaleViewController.swift index ad7e0844c..34f4d9f2c 100644 --- a/kDrive/UI/View/Upsale/NoDriveUpsaleViewController.swift +++ b/kDrive/UI/View/Upsale/NoDriveUpsaleViewController.swift @@ -22,6 +22,8 @@ import kDriveResources import UIKit public class NoDriveUpsaleViewController: UpsaleViewController { + var dismissCallback: (() -> Void)? + override func configureButtons() { dismissButton.style = .primaryButton freeTrialButton.setTitle(KDriveStrings.Localizable.obtainkDriveAdFreeTrialButton, for: .normal) @@ -39,5 +41,6 @@ public class NoDriveUpsaleViewController: UpsaleViewController { @objc public func dismissViewController() { dismiss(animated: true, completion: nil) + dismissCallback?() } } diff --git a/kDrive/UI/View/Upsale/UpsaleViewController.swift b/kDrive/UI/View/Upsale/UpsaleViewController.swift index bc1c28f40..a6bf7ba8d 100644 --- a/kDrive/UI/View/Upsale/UpsaleViewController.swift +++ b/kDrive/UI/View/Upsale/UpsaleViewController.swift @@ -22,6 +22,9 @@ import kDriveResources import UIKit public class UpsaleViewController: UIViewController { + var loginCallback: (() -> Void)? + var freeTrialCallback: (() -> Void)? + let titleImageView = UIImageView() let titleLabel: UILabel = { @@ -217,12 +220,12 @@ public class UpsaleViewController: UIViewController { } @objc public func freeTrial() { - // TODO: Hook free trial dismiss(animated: true, completion: nil) + freeTrialCallback?() } @objc public func login() { - // TODO: Hook login dismiss(animated: true, completion: nil) + loginCallback?() } } diff --git a/kDriveCore/Data/Api/DriveApiFetcher.swift b/kDriveCore/Data/Api/DriveApiFetcher.swift index a3cd50e5e..934afc45f 100644 --- a/kDriveCore/Data/Api/DriveApiFetcher.swift +++ b/kDriveCore/Data/Api/DriveApiFetcher.swift @@ -549,6 +549,42 @@ public class DriveApiFetcher: ApiFetcher { public func file(_ file: AbstractFile) async throws -> File { try await perform(request: authenticatedRequest(.file(file))) } + + public func importShareLinkFiles(sourceDriveId: Int, + destinationDriveId: Int, + fileIds: [Int]?, + exceptIds: [Int]?, + password: String? = nil) async throws -> ValidServerResponse { + let destinationDrive = ProxyDrive(id: destinationDriveId) + let importShareLinkFiles = Endpoint.importShareLinkFiles(destinationDrive: destinationDrive) + var requestParameters: Parameters = [ + APIPublicShareParameter.sourceDriveId: sourceDriveId + ] + + if let fileIds, !fileIds.isEmpty { + requestParameters[APIPublicShareParameter.fileIds] = fileIds + } else if let exceptIds, !exceptIds.isEmpty { + requestParameters[APIPublicShareParameter.exceptFileIds] = exceptIds + } + + if let password { + requestParameters[APIPublicShareParameter.password] = password + } + + let result: ValidServerResponse = try await perform(request: authenticatedRequest( + importShareLinkFiles, + method: .post, + parameters: requestParameters + )) + return result + } +} + +enum APIPublicShareParameter { + static let sourceDriveId = "source_drive_id" + static let fileIds = "file_ids" + static let exceptFileIds = "except_file_ids" + static let password = "password" } class SyncedAuthenticator: OAuthAuthenticator { diff --git a/kDriveCore/Data/Api/Endpoint+Share.swift b/kDriveCore/Data/Api/Endpoint+Share.swift index 349c7d036..796a00c7a 100644 --- a/kDriveCore/Data/Api/Endpoint+Share.swift +++ b/kDriveCore/Data/Api/Endpoint+Share.swift @@ -88,8 +88,8 @@ public extension Endpoint { return Self.shareUrlV1.appending(path: "/share/\(driveId)/\(linkUuid)/preview/text/\(fileId)") } - /// Add to my Drive - static func importShareLinkFiles(driveId: Int) -> Endpoint { - return Endpoint(hostKeypath: \.driveHost, path: "/2/drive").appending(path: "/\(driveId)/imports/sharelink") + /// Add Public Share to my Drive + static func importShareLinkFiles(destinationDrive: AbstractDrive) -> Endpoint { + return Endpoint.driveInfoV2(drive: destinationDrive).appending(path: "/imports/sharelink") } } diff --git a/kDriveCore/Data/Api/PublicShareApiFetcher.swift b/kDriveCore/Data/Api/PublicShareApiFetcher.swift index 8cc14fb95..8005dc1f2 100644 --- a/kDriveCore/Data/Api/PublicShareApiFetcher.swift +++ b/kDriveCore/Data/Api/PublicShareApiFetcher.swift @@ -29,13 +29,6 @@ public enum PublicShareLimitation: String { case expired = "link_is_not_valid" } -enum APIPublicShareParameter { - static let sourceDriveId = "source_drive_id" - static let fileIds = "file_ids" - static let exceptFileIds = "except_file_ids" - static let password = "password" -} - public class PublicShareApiFetcher: ApiFetcher { override public init() { super.init() @@ -97,29 +90,4 @@ public extension PublicShareApiFetcher { let shareLinkFiles: ValidServerResponse<[File]> = try await perform(request: request) return shareLinkFiles } - - func importShareLinkFiles(sourceDriveId: Int, - destinationDriveId: Int, - fileIds: [Int]?, - exceptIds: [Int]?, - password: String? = nil) async throws -> ValidServerResponse { - let importShareLinkFilesUrl = Endpoint.importShareLinkFiles(driveId: destinationDriveId).url - var requestParameters: [String: AnyHashable] = [ - APIPublicShareParameter.sourceDriveId: sourceDriveId - ] - - if let fileIds, !fileIds.isEmpty { - requestParameters[APIPublicShareParameter.fileIds] = fileIds - } else if let exceptIds, !exceptIds.isEmpty { - requestParameters[APIPublicShareParameter.exceptFileIds] = exceptIds - } - - if let password { - requestParameters[APIPublicShareParameter.password] = password - } - - let request = Session.default.request(importShareLinkFilesUrl) - let externalImport: ValidServerResponse = try await perform(request: request) - return externalImport - } }