From 66508e9dcabf1b3b3886676462ed0f81eb27dce6 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Fri, 16 Aug 2024 13:47:42 +0200 Subject: [PATCH] network: Share some api routes for all supported platforms --- .../network/repositories/UploadRepository.kt | 4 ++-- .../network/requests/UploadRequest.kt | 5 +++-- .../network/utils/ApiRoutes.kt | 16 ---------------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/repositories/UploadRepository.kt b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/repositories/UploadRepository.kt index 5478d92e..08e2dfb1 100644 --- a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/repositories/UploadRepository.kt +++ b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/repositories/UploadRepository.kt @@ -107,10 +107,10 @@ class UploadRepository internal constructor(private val uploadRequest: UploadReq containerUUID: String, fileUUID: String, chunkIndex: Int, - lastChunk: Boolean, + isLastChunk: Boolean, data: ByteArray, ): Boolean { - return uploadRequest.uploadChunk(uploadHost, containerUUID, fileUUID, chunkIndex, lastChunk, data) + return uploadRequest.uploadChunk(uploadHost, containerUUID, fileUUID, chunkIndex, isLastChunk, data) } @Throws( diff --git a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/requests/UploadRequest.kt b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/requests/UploadRequest.kt index 80a80573..b837052c 100644 --- a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/requests/UploadRequest.kt +++ b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/requests/UploadRequest.kt @@ -26,6 +26,7 @@ import com.infomaniak.multiplatform_swisstransfer.network.models.upload.request. import com.infomaniak.multiplatform_swisstransfer.network.models.upload.request.ResendEmailCodeBody import com.infomaniak.multiplatform_swisstransfer.network.models.upload.request.VerifyEmailCodeBody import com.infomaniak.multiplatform_swisstransfer.network.utils.ApiRoutes +import com.infomaniak.multiplatform_swisstransfer.network.utils.SharedApiRoutes import io.ktor.client.HttpClient import io.ktor.client.request.post import io.ktor.client.request.setBody @@ -54,11 +55,11 @@ internal class UploadRequest(json: Json, httpClient: HttpClient) : BaseRequest(j containerUUID: String, fileUUID: String, chunkIndex: Int, - lastChunk: Boolean, + isLastChunk: Boolean, data: ByteArray, ): Boolean { val httpResponse = httpClient.post( - urlString = ApiRoutes.uploadChunk(uploadHost, containerUUID, fileUUID, chunkIndex, lastChunk) + urlString = SharedApiRoutes.uploadChunk(uploadHost, containerUUID, fileUUID, chunkIndex, isLastChunk) ) { setBody(data) } diff --git a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/ApiRoutes.kt b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/ApiRoutes.kt index 75782485..14c15223 100644 --- a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/ApiRoutes.kt +++ b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/ApiRoutes.kt @@ -25,14 +25,6 @@ internal object ApiRoutes { fun getTransfer(linkUUID: String): String { return "links/$linkUUID" } - - fun downloadFiles(downloadHost: String, linkUUID: String): String { - return "https://$downloadHost/api/download/$linkUUID" - } - - fun downloadFile(downloadHost: String, linkUUID: String, fileUUID: String?): String { - return "${downloadFiles(downloadHost, linkUUID)}/$fileUUID" - } //endRegion //region Upload @@ -40,13 +32,5 @@ internal object ApiRoutes { const val verifyEmailCode = "emails-validation" const val resendEmailCode = "$verifyEmailCode/resend" const val finishUpload = "uploadComplete" - - fun uploadChunk(uploadHost: String, containerUUID: String, fileUUID: String, chunkIndex: Int, lastChunk: Boolean): String { - return "https://$uploadHost/api/uploadChunk/$containerUUID/$fileUUID/$chunkIndex/${lastChunk.int()}" - } - //endregion - - //region Utils - private fun Boolean.int() = if (this) 1 else 0 //endregion }