From cfb2eb9e8013631bf0a9a41aaa4d320ff366789e Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Wed, 11 Dec 2024 13:11:04 +0100 Subject: [PATCH 1/4] feat: Add authorEmailToken --- .../common/interfaces/upload/UploadSession.kt | 1 + .../multiplatform_swisstransfer/data/NewUploadSession.kt | 1 + .../network/models/upload/request/InitUploadBody.kt | 2 ++ 3 files changed, 4 insertions(+) diff --git a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/upload/UploadSession.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/upload/UploadSession.kt index a393d67a..e8f7678a 100644 --- a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/upload/UploadSession.kt +++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/upload/UploadSession.kt @@ -25,6 +25,7 @@ interface UploadSession { val uuid: String val duration: ValidityPeriod get() = ValidityPeriod.THIRTY val authorEmail: String + val authorEmailToken: String? val password: String val message: String val numberOfDownload: DownloadLimit get() = DownloadLimit.TWO_HUNDRED_FIFTY diff --git a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/data/NewUploadSession.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/data/NewUploadSession.kt index 132ddc87..880a23a4 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/data/NewUploadSession.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/data/NewUploadSession.kt @@ -27,6 +27,7 @@ import com.infomaniak.multiplatform_swisstransfer.common.models.ValidityPeriod data class NewUploadSession( override val duration: ValidityPeriod, override val authorEmail: String, + override val authorEmailToken: String?, override val password: String, override val message: String, override val numberOfDownload: DownloadLimit, diff --git a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/models/upload/request/InitUploadBody.kt b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/models/upload/request/InitUploadBody.kt index a45868d0..00e2146f 100644 --- a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/models/upload/request/InitUploadBody.kt +++ b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/models/upload/request/InitUploadBody.kt @@ -28,6 +28,7 @@ import kotlinx.serialization.json.Json class InitUploadBody( val duration: String = "", val authorEmail: String = "", + val authorEmailToken: String? = null, val password: String = "", val message: String = "", val sizeOfUpload: Long = 0L, @@ -43,6 +44,7 @@ class InitUploadBody( constructor(uploadSession: UploadSession, recaptcha: String) : this( duration = uploadSession.duration.value.toString(), authorEmail = uploadSession.authorEmail, + authorEmailToken = uploadSession.authorEmailToken, password = uploadSession.password, message = uploadSession.message, sizeOfUpload = uploadSession.files.sumOf { it.size }, From 94aa25fdf6a12032269d495d37a76a20cf2af7b2 Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Thu, 12 Dec 2024 13:43:49 +0100 Subject: [PATCH 2/4] feat(UploadRequest): Remove null keys encode to json --- .../network/requests/UploadRequest.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 9a7c0c41..f5954272 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 @@ -36,11 +36,16 @@ import io.ktor.http.contentType import io.ktor.http.isSuccess import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.encodeToJsonElement internal class UploadRequest(json: Json, httpClient: HttpClient) : BaseRequest(json, httpClient) { suspend fun initUpload(initUploadBody: InitUploadBody): InitUploadResponseApi { - return post(url = createUrl(ApiRoutes.initUpload), initUploadBody) + val nullableJson = Json(json) { + explicitNulls = false + } + val encodedInitUploadBody = nullableJson.encodeToJsonElement(initUploadBody) + return post(url = createUrl(ApiRoutes.initUpload), encodedInitUploadBody) } suspend fun verifyEmailCode(verifyEmailCodeBody: VerifyEmailCodeBody): AuthorEmailToken { From 929dd75fa84531f1808565cdeedf282f259801b8 Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Thu, 12 Dec 2024 14:26:22 +0100 Subject: [PATCH 3/4] fix(UploadSessionDB): Add authorEmailToken --- .../database/models/upload/UploadSessionDB.kt | 1 + .../multiplatform_swisstransfer/database/dataset/DummyUpload.kt | 1 + 2 files changed, 2 insertions(+) diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/upload/UploadSessionDB.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/upload/UploadSessionDB.kt index f85e5c93..5dea3b65 100644 --- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/upload/UploadSessionDB.kt +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/upload/UploadSessionDB.kt @@ -33,6 +33,7 @@ class UploadSessionDB() : UploadSession, RealmObject { override var uuid: String = RealmUUID.random().toString() private var _duration: Int = AppSettingsDB.DEFAULT_VALIDITY_PERIOD.value override var authorEmail: String = "" + override var authorEmailToken: String? = null override var password: String = "" override var message: String = "" private var _numberOfDownload: Int = AppSettingsDB.DEFAULT_DOWNLOAD_LIMIT.value diff --git a/STDatabase/src/commonTest/kotlin/com/infomaniak/multiplatform_swisstransfer/database/dataset/DummyUpload.kt b/STDatabase/src/commonTest/kotlin/com/infomaniak/multiplatform_swisstransfer/database/dataset/DummyUpload.kt index 925570f4..a38f04d4 100644 --- a/STDatabase/src/commonTest/kotlin/com/infomaniak/multiplatform_swisstransfer/database/dataset/DummyUpload.kt +++ b/STDatabase/src/commonTest/kotlin/com/infomaniak/multiplatform_swisstransfer/database/dataset/DummyUpload.kt @@ -44,6 +44,7 @@ object DummyUpload { override val uuid: String = "upload1" override val duration: ValidityPeriod = ValidityPeriod.THIRTY override val authorEmail: String = "" + override val authorEmailToken: String? = null override val password: String = "" override val message: String = "" override val numberOfDownload: DownloadLimit = DownloadLimit.ONE From 2129ccd00a5c13e6692e841400c5cb96b2a2698d Mon Sep 17 00:00:00 2001 From: Vincent TE Date: Thu, 12 Dec 2024 16:10:45 +0100 Subject: [PATCH 4/4] fix: Use encodeToString instead of encodeToJsonElement --- .../network/requests/UploadRequest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 f5954272..74d08246 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 @@ -34,9 +34,9 @@ import io.ktor.client.request.setBody import io.ktor.http.ContentType import io.ktor.http.contentType import io.ktor.http.isSuccess +import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.encodeToJsonElement internal class UploadRequest(json: Json, httpClient: HttpClient) : BaseRequest(json, httpClient) { @@ -44,7 +44,7 @@ internal class UploadRequest(json: Json, httpClient: HttpClient) : BaseRequest(j val nullableJson = Json(json) { explicitNulls = false } - val encodedInitUploadBody = nullableJson.encodeToJsonElement(initUploadBody) + val encodedInitUploadBody = nullableJson.encodeToString(initUploadBody) return post(url = createUrl(ApiRoutes.initUpload), encodedInitUploadBody) }