Skip to content

Commit

Permalink
feat: Handle transfer with password
Browse files Browse the repository at this point in the history
  • Loading branch information
sirambd committed Nov 14, 2024
1 parent fd223ac commit 432b221
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class TransferManager internal constructor(
)
suspend fun addTransferByLinkUUID(linkUUID: String, uploadSession: UploadSession?): Unit = withContext(Dispatchers.IO) {
runCatching {
addTransfer(transferRepository.getTransferByLinkUUID(linkUUID).data, TransferDirection.SENT)
addTransfer(transferRepository.getTransferByLinkUUID(linkUUID, uploadSession?.password).data, TransferDirection.SENT)
}.onFailure { exception ->
when {
uploadSession == null -> return@withContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class TransferRepository internal constructor(private val transferRequest: Trans
NetworkException::class,
UnknownException::class,
)
suspend fun getTransferByLinkUUID(linkUUID: String): ApiResponse<TransferApi> = transferRequest.getTransfer(linkUUID)
suspend fun getTransferByLinkUUID(linkUUID: String, password: String? = null): ApiResponse<TransferApi> {
return transferRequest.getTransfer(linkUUID, password)
}

@Throws(
CancellationException::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,22 @@ import com.infomaniak.multiplatform_swisstransfer.network.models.ApiResponse
import com.infomaniak.multiplatform_swisstransfer.network.models.transfer.TransferApi
import com.infomaniak.multiplatform_swisstransfer.network.utils.ApiRoutes
import io.ktor.client.HttpClient
import io.ktor.http.HttpHeaders
import kotlinx.serialization.json.Json
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi

internal class TransferRequest(json: Json, httpClient: HttpClient) : BaseRequest(json, httpClient) {

suspend fun getTransfer(linkUUID: String): ApiResponse<TransferApi> {
return get(url = createUrl(ApiRoutes.getTransfer(linkUUID)))
@OptIn(ExperimentalEncodingApi::class)
suspend fun getTransfer(linkUUID: String, password: String? = null): ApiResponse<TransferApi> {
return get(
url = createUrl(ApiRoutes.getTransfer(linkUUID)),
appendHeaders = {
if (password?.isNotEmpty() == true) {
append(HttpHeaders.Authorization, Base64.Default.encode(password.encodeToByteArray()))
}
}
)
}
}

0 comments on commit 432b221

Please sign in to comment.