From 21ff9ac38afa235622032c11e6a56dcf9fda0126 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Fri, 16 Aug 2024 13:45:33 +0200 Subject: [PATCH 1/4] network: Add Boolean extension --- .../network/utils/BooleanExt.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/BooleanExt.kt diff --git a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/BooleanExt.kt b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/BooleanExt.kt new file mode 100644 index 00000000..51c70afc --- /dev/null +++ b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/BooleanExt.kt @@ -0,0 +1,21 @@ +/* + * Infomaniak SwissTransfer - Multiplatform + * Copyright (C) 2024 Infomaniak Network SA + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.infomaniak.multiplatform_swisstransfer.network.utils + +fun Boolean.int() = if (this) 1 else 0 \ No newline at end of file From b5a33eeb8a4fe07f31c1f0972ddcfa1520cbd696 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Fri, 16 Aug 2024 13:46:25 +0200 Subject: [PATCH 2/4] network: Add SharedApiRoute to expose all urls with kmp --- .../network/utils/SharedApiRoutes.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/SharedApiRoutes.kt diff --git a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/SharedApiRoutes.kt b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/SharedApiRoutes.kt new file mode 100644 index 00000000..971299a6 --- /dev/null +++ b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/SharedApiRoutes.kt @@ -0,0 +1,34 @@ +/* + * Infomaniak SwissTransfer - Multiplatform + * Copyright (C) 2024 Infomaniak Network SA + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.infomaniak.multiplatform_swisstransfer.network.utils + +object SharedApiRoutes { + + 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" + } + + fun uploadChunk(uploadHost: String, containerUUID: String, fileUUID: String, chunkIndex: Int, isLastChunk: Boolean): String { + return "https://$uploadHost/api/uploadChunk/$containerUUID/$fileUUID/$chunkIndex/${isLastChunk.int()}" + } +} \ No newline at end of file From 66508e9dcabf1b3b3886676462ed0f81eb27dce6 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Fri, 16 Aug 2024 13:47:42 +0200 Subject: [PATCH 3/4] 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 } From 95fa53ed82b52776b033b25c8c5005a66b78e8f5 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Fri, 16 Aug 2024 13:54:49 +0200 Subject: [PATCH 4/4] Refactor new lines --- .../multiplatform_swisstransfer/network/utils/BooleanExt.kt | 2 +- .../network/utils/SharedApiRoutes.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/BooleanExt.kt b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/BooleanExt.kt index 51c70afc..f114180a 100644 --- a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/BooleanExt.kt +++ b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/BooleanExt.kt @@ -18,4 +18,4 @@ package com.infomaniak.multiplatform_swisstransfer.network.utils -fun Boolean.int() = if (this) 1 else 0 \ No newline at end of file +fun Boolean.int() = if (this) 1 else 0 diff --git a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/SharedApiRoutes.kt b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/SharedApiRoutes.kt index 971299a6..a1aa2a4d 100644 --- a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/SharedApiRoutes.kt +++ b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/utils/SharedApiRoutes.kt @@ -31,4 +31,4 @@ object SharedApiRoutes { fun uploadChunk(uploadHost: String, containerUUID: String, fileUUID: String, chunkIndex: Int, isLastChunk: Boolean): String { return "https://$uploadHost/api/uploadChunk/$containerUUID/$fileUUID/$chunkIndex/${isLastChunk.int()}" } -} \ No newline at end of file +}