Send app package and version in sendMailLoginCode

This commit is contained in:
Jonas Lochmann 2024-07-08 02:00:00 +02:00
parent 314f9af6ef
commit a2e553c6f5
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36

View file

@ -146,7 +146,11 @@ class HttpServerApi(private val endpointWithoutSlashAtEnd: String): ServerApi {
private suspend fun sendMailLoginCode(mail: String, locale: String, deviceAuthToken: String?, skipDeviceVerification: Boolean): String = withDeviceVerification (enable = !skipDeviceVerification) { client -> private suspend fun sendMailLoginCode(mail: String, locale: String, deviceAuthToken: String?, skipDeviceVerification: Boolean): String = withDeviceVerification (enable = !skipDeviceVerification) { client ->
postJsonRequest( postJsonRequest(
"auth/send-mail-login-code-v2", "auth/send-mail-login-code-v2",
client = client client = client,
transformRequest = { it
.header("X-Client-Package", BuildConfig.APPLICATION_ID)
.header("X-Client-Version", BuildConfig.VERSION_NAME)
}
) { writer -> ) { writer ->
writer.beginObject() writer.beginObject()
writer.name(MAIL).value(mail) writer.name(MAIL).value(mail)
@ -659,10 +663,17 @@ class HttpServerApi(private val endpointWithoutSlashAtEnd: String): ServerApi {
private suspend fun postJsonRequest( private suspend fun postJsonRequest(
path: String, path: String,
client: OkHttpClient = httpClient, client: OkHttpClient = httpClient,
requestBody: (writer: JsonWriter) -> Unit transformRequest: (Request.Builder) -> Request.Builder = { it },
requestBody: (writer: JsonWriter) -> Unit,
): Response { ): Response {
if (!sendContentLength) { if (!sendContentLength) {
val response = postJsonRequest(path, requestBody, transmitContentLength = false, client = client) val response = postJsonRequest(
path,
requestBody,
transmitContentLength = false,
client = client,
transformRequest = transformRequest
)
if (response.code != 411) return response if (response.code != 411) return response
@ -671,14 +682,21 @@ class HttpServerApi(private val endpointWithoutSlashAtEnd: String): ServerApi {
sendContentLength = true sendContentLength = true
} }
return postJsonRequest(path, requestBody, transmitContentLength = true, client = client) return postJsonRequest(
path,
requestBody,
transmitContentLength = true,
client = client,
transformRequest = transformRequest
)
} }
private suspend fun postJsonRequest( private suspend fun postJsonRequest(
path: String, path: String,
requestBody: (writer: JsonWriter) -> Unit, requestBody: (writer: JsonWriter) -> Unit,
transmitContentLength: Boolean, transmitContentLength: Boolean,
client: OkHttpClient = httpClient client: OkHttpClient = httpClient,
transformRequest: (Request.Builder) -> Request.Builder = { it }
): Response { ): Response {
val body = createJsonRequestBody(requestBody, transmitContentLength) val body = createJsonRequestBody(requestBody, transmitContentLength)
@ -687,6 +705,7 @@ class HttpServerApi(private val endpointWithoutSlashAtEnd: String): ServerApi {
.url("$endpointWithoutSlashAtEnd/$path") .url("$endpointWithoutSlashAtEnd/$path")
.post(body) .post(body)
.header("Content-Encoding", "gzip") .header("Content-Encoding", "gzip")
.let { transformRequest(it) }
.build() .build()
).waitForResponse() ).waitForResponse()
} }