Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Bump core #1414

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Tuist/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/ios-core",
"state" : {
"revision" : "9fdaf17dea8d950a520d240f21391be6195239fd",
"version" : "13.1.0"
"revision" : "c3a442b5bd2fb67680aa252638773c4d7d1551ad",
"version" : "14.0.0"
}
},
{
"identity" : "ios-core-ui",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/ios-core-ui",
"state" : {
"revision" : "824ac002c136fc706321e8f12f8c7736bebd8680",
"version" : "16.4.0"
"revision" : "fc37b5e6e96e38f232f62bd03d322ea6951c1c0f",
"version" : "17.0.0"
}
},
{
Expand All @@ -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"
}
},
{
Expand Down Expand Up @@ -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"
}
},
{
Expand Down
6 changes: 3 additions & 3 deletions Tuist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
8 changes: 4 additions & 4 deletions kDriveCore/Data/Api/DriveApiFetcher+Upload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
38 changes: 22 additions & 16 deletions kDriveCore/Data/Api/DriveApiFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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<T: Decodable>(request: DataRequest,
decoder: JSONDecoder = ApiFetcher.decoder) async throws -> ValidServerResponse<T> {
overrideDecoder: JSONDecoder? = nil) async throws -> ValidServerResponse<T> {
do {
return try await super.perform(request: request)
} catch InfomaniakError.apiError(let apiError) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
Expand All @@ -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))
}
Expand Down Expand Up @@ -511,7 +517,7 @@ public class DriveApiFetcher: ApiFetcher {
password: String? = nil) async throws -> ValidServerResponse<FileExternalImport> {
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
Expand Down
7 changes: 2 additions & 5 deletions kDriveCore/Data/Api/PublicShareApiFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Decodable>(request: DataRequest,
decoder: JSONDecoder = ApiFetcher.decoder) async throws -> ValidServerResponse<T> {
overrideDecoder: JSONDecoder? = nil) async throws -> ValidServerResponse<T> {
let decoder = overrideDecoder ?? self.decoder
let validatedRequest = request.validate(statusCode: PublicShareApiFetcher.handledHttpStatus)
let dataResponse = await validatedRequest.serializingDecodable(ApiResponse<T>.self,
automaticallyCancelling: true,
Expand Down
5 changes: 3 additions & 2 deletions kDriveCore/Data/UploadQueue/Operation/UploadOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<UploadedChunk>.self, from: data).data else {

guard let uploadedChunk = try? DriveApiFetcher.decoder.decode(ApiResponse<UploadedChunk>.self, from: data).data else {
Log.uploadOperation("parsing error:\(String(describing: error)) ufid:\(uploadFileId)", level: .error)
throw ErrorDomain.parseError
}
Expand Down Expand Up @@ -460,7 +461,7 @@ public final class UploadOperation: AsynchronousOperation, UploadOperationable {

var driveError = DriveError.serverError
if let data,
let apiError = try? ApiFetcher.decoder.decode(ApiResponse<Empty>.self, from: data).error {
let apiError = try? DriveApiFetcher.decoder.decode(ApiResponse<Empty>.self, from: data).error {
driveError = DriveError(apiError: apiError)
}

Expand Down
Loading