diff --git a/Tuist/Package.resolved b/Tuist/Package.resolved index 69e1c85f1..4496ba87e 100644 --- a/Tuist/Package.resolved +++ b/Tuist/Package.resolved @@ -86,8 +86,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Infomaniak/ios-core", "state" : { - "revision" : "9fdaf17dea8d950a520d240f21391be6195239fd", - "version" : "13.1.0" + "revision" : "c3a442b5bd2fb67680aa252638773c4d7d1551ad", + "version" : "14.0.0" } }, { @@ -95,8 +95,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Infomaniak/ios-core-ui", "state" : { - "revision" : "824ac002c136fc706321e8f12f8c7736bebd8680", - "version" : "16.4.0" + "revision" : "fc37b5e6e96e38f232f62bd03d322ea6951c1c0f", + "version" : "17.0.0" } }, { @@ -122,8 +122,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Infomaniak/ios-version-checker", "state" : { - "revision" : "7027616a4fc3d5b1464f55c934111724356ebac3", - "version" : "8.0.0" + "revision" : "4f7303c66e8bfd6a0ca7fb21fd35838b58c72219", + "version" : "9.0.0" } }, { @@ -302,8 +302,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio.git", "state" : { - "revision" : "ba72f31e11275fc5bf060c966cf6c1f36842a291", - "version" : "2.79.0" + "revision" : "dff45738d84a53dbc8ee899c306b3a7227f54f89", + "version" : "2.80.0" } }, { diff --git a/Tuist/Package.swift b/Tuist/Package.swift index c394b2a29..be1b55181 100644 --- a/Tuist/Package.swift +++ b/Tuist/Package.swift @@ -19,12 +19,12 @@ let package = Package( dependencies: [ .package(url: "https://github.com/apple/swift-algorithms", .upToNextMajor(from: "1.2.0")), .package(url: "https://github.com/Alamofire/Alamofire", .upToNextMajor(from: "5.2.2")), - .package(url: "https://github.com/Infomaniak/ios-core", .upToNextMajor(from: "13.0.0")), - .package(url: "https://github.com/Infomaniak/ios-core-ui", .upToNextMajor(from: "16.0.0")), + .package(url: "https://github.com/Infomaniak/ios-core", .upToNextMajor(from: "14.0.0")), + .package(url: "https://github.com/Infomaniak/ios-core-ui", .upToNextMajor(from: "17.0.0")), .package(url: "https://github.com/Infomaniak/ios-login", .upToNextMajor(from: "7.2.0")), .package(url: "https://github.com/Infomaniak/ios-dependency-injection", .upToNextMajor(from: "2.0.3")), .package(url: "https://github.com/Infomaniak/swift-concurrency", .upToNextMajor(from: "1.0.0")), - .package(url: "https://github.com/Infomaniak/ios-version-checker", .upToNextMajor(from: "8.0.0")), + .package(url: "https://github.com/Infomaniak/ios-version-checker", .upToNextMajor(from: "9.0.0")), .package(url: "https://github.com/Infomaniak/LocalizeKit", .upToNextMajor(from: "1.0.2")), .package(url: "https://github.com/realm/realm-swift", .upToNextMajor(from: "10.52.0")), .package(url: "https://github.com/SCENEE/FloatingPanel", .upToNextMajor(from: "2.0.0")), diff --git a/kDriveCore/Data/Api/DriveApiFetcher+Upload.swift b/kDriveCore/Data/Api/DriveApiFetcher+Upload.swift index d979af8d7..98fcb2ab6 100644 --- a/kDriveCore/Data/Api/DriveApiFetcher+Upload.swift +++ b/kDriveCore/Data/Api/DriveApiFetcher+Upload.swift @@ -40,7 +40,7 @@ enum APIUploadParameter: String { } public extension DriveApiFetcher { - internal typealias APIParameters = [APIUploadParameter: Any?] + internal typealias APIParameters = [APIUploadParameter: Encodable?] /// Starts a session to upload a file in multiple parts /// /// https://developer.infomaniak.com/docs/api/post/2/drive/%7Bdrive_id%7D/upload/session/start @@ -242,9 +242,9 @@ public extension DriveApiFetcher { } } -extension [APIUploadParameter: Any?] { - func toParameters() -> Parameters { - var parameters = Parameters() +extension [APIUploadParameter: Encodable?] { + func toParameters() -> EncodableParameters { + var parameters = EncodableParameters() for rawParameter in self { if let nonNilValue = rawParameter.value { parameters[rawParameter.key.rawValue] = nonNilValue diff --git a/kDriveCore/Data/Api/DriveApiFetcher.swift b/kDriveCore/Data/Api/DriveApiFetcher.swift index bcfc4407e..7b2d6f508 100644 --- a/kDriveCore/Data/Api/DriveApiFetcher.swift +++ b/kDriveCore/Data/Api/DriveApiFetcher.swift @@ -25,15 +25,6 @@ import Kingfisher import Sentry import UIKit -public extension ApiFetcher { - convenience init(token: ApiToken, delegate: RefreshTokenDelegate) { - self.init() - createAuthenticatedSession(token, - authenticator: SyncedAuthenticator(refreshTokenDelegate: delegate), - additionalAdapters: [RequestContextIdAdaptor(), UserAgentAdapter()]) - } -} - public class AuthenticatedImageRequestModifier: ImageDownloadRequestModifier { weak var apiFetcher: ApiFetcher? @@ -53,18 +44,33 @@ public class AuthenticatedImageRequestModifier: ImageDownloadRequestModifier { } public class DriveApiFetcher: ApiFetcher { + public static var decoder: JSONDecoder = { + let decoder = JSONDecoder() + decoder.dateDecodingStrategy = .secondsSince1970 + decoder.keyDecodingStrategy = .convertFromSnakeCase + return decoder + }() + @LazyInjectService var accountManager: AccountManageable @LazyInjectService var tokenable: InfomaniakNetworkLoginable public var authenticatedKF: AuthenticatedImageRequestModifier! - override public init() { - super.init() + public init() { + super.init(decoder: Self.decoder) + authenticatedKF = AuthenticatedImageRequestModifier(apiFetcher: self) + } + + public convenience init(token: ApiToken, delegate: RefreshTokenDelegate) { + self.init() + createAuthenticatedSession(token, + authenticator: SyncedAuthenticator(refreshTokenDelegate: delegate), + additionalAdapters: [RequestContextIdAdaptor(), UserAgentAdapter()]) authenticatedKF = AuthenticatedImageRequestModifier(apiFetcher: self) } override public func perform(request: DataRequest, - decoder: JSONDecoder = ApiFetcher.decoder) async throws -> ValidServerResponse { + overrideDecoder: JSONDecoder? = nil) async throws -> ValidServerResponse { do { return try await super.perform(request: request) } catch InfomaniakError.apiError(let apiError) { @@ -395,7 +401,7 @@ public class DriveApiFetcher: ApiFetcher { } public func restore(file: ProxyFile, in directory: ProxyFile? = nil) async throws -> CancelableResponse { - let parameters: Parameters? + let parameters: EncodableParameters? if let directory { parameters = ["destination_directory_id": directory.id] } else { @@ -433,7 +439,7 @@ public class DriveApiFetcher: ApiFetcher { } public func add(drive: AbstractDrive, category: Category, to files: [ProxyFile]) async throws -> [CategoryResponse] { - let parameters: Parameters = ["file_ids": files.map(\.id)] + let parameters: EncodableParameters = ["file_ids": files.map(\.id)] return try await perform(request: authenticatedRequest(.fileCategory(drive: drive, category: category), method: .post, parameters: parameters)) } @@ -443,7 +449,7 @@ public class DriveApiFetcher: ApiFetcher { } public func remove(drive: AbstractDrive, category: Category, from files: [ProxyFile]) async throws -> [CategoryResponse] { - let parameters: Parameters = ["file_ids": files.map(\.id)] + let parameters: EncodableParameters = ["file_ids": files.map(\.id)] return try await perform(request: authenticatedRequest(.fileCategory(drive: drive, category: category), method: .delete, parameters: parameters)) } @@ -511,7 +517,7 @@ public class DriveApiFetcher: ApiFetcher { password: String? = nil) async throws -> ValidServerResponse { let destinationDrive = ProxyDrive(id: destinationDriveId) let importShareLinkFiles = Endpoint.importShareLinkFiles(destinationDrive: destinationDrive) - var requestParameters: Parameters = [ + var requestParameters: EncodableParameters = [ PublicShareAPIParameters.sourceDriveId: sourceDriveId, PublicShareAPIParameters.destinationFolderId: destinationFolderId, PublicShareAPIParameters.sharelinkUuid: sharelinkUuid diff --git a/kDriveCore/Data/Api/PublicShareApiFetcher.swift b/kDriveCore/Data/Api/PublicShareApiFetcher.swift index b97c52e47..735a14f64 100644 --- a/kDriveCore/Data/Api/PublicShareApiFetcher.swift +++ b/kDriveCore/Data/Api/PublicShareApiFetcher.swift @@ -30,15 +30,12 @@ public enum PublicShareLimitation: String { } public class PublicShareApiFetcher: ApiFetcher { - override public init() { - super.init() - } - /// All status including 401 are handled by our code. A locked public share will 401, therefore we need to support it. private static var handledHttpStatus = Set(200 ... 500) override public func perform(request: DataRequest, - decoder: JSONDecoder = ApiFetcher.decoder) async throws -> ValidServerResponse { + overrideDecoder: JSONDecoder? = nil) async throws -> ValidServerResponse { + let decoder = overrideDecoder ?? self.decoder let validatedRequest = request.validate(statusCode: PublicShareApiFetcher.handledHttpStatus) let dataResponse = await validatedRequest.serializingDecodable(ApiResponse.self, automaticallyCancelling: true, diff --git a/kDriveCore/Data/UploadQueue/Operation/UploadOperation.swift b/kDriveCore/Data/UploadQueue/Operation/UploadOperation.swift index 69f00cec7..3b7d3c60a 100644 --- a/kDriveCore/Data/UploadQueue/Operation/UploadOperation.swift +++ b/kDriveCore/Data/UploadQueue/Operation/UploadOperation.swift @@ -362,7 +362,8 @@ public final class UploadOperation: AsynchronousOperation, UploadOperationable { private func uploadCompletionSuccess(data: Data, response: URLResponse?, error: Error?) async throws { Log.uploadOperation("completion successful \(uploadFileId)") - guard let uploadedChunk = try? ApiFetcher.decoder.decode(ApiResponse.self, from: data).data else { + + guard let uploadedChunk = try? DriveApiFetcher.decoder.decode(ApiResponse.self, from: data).data else { Log.uploadOperation("parsing error:\(String(describing: error)) ufid:\(uploadFileId)", level: .error) throw ErrorDomain.parseError } @@ -460,7 +461,7 @@ public final class UploadOperation: AsynchronousOperation, UploadOperationable { var driveError = DriveError.serverError if let data, - let apiError = try? ApiFetcher.decoder.decode(ApiResponse.self, from: data).error { + let apiError = try? DriveApiFetcher.decoder.decode(ApiResponse.self, from: data).error { driveError = DriveError(apiError: apiError) }