fix(app): remove Moshi @Json annotations from MeResp after Retrofit cleanup
This commit is contained in:
@@ -2,33 +2,13 @@ package app.klottr.net
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import app.klottr.BuildConfig
|
||||
import app.klottr.net.KlottrApiShared
|
||||
import app.klottr.util.Auth
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Response
|
||||
import okhttp3.ResponseBody
|
||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Response as RResponse
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||
import retrofit2.http.*
|
||||
import retrofit2.http.Url
|
||||
|
||||
import java.io.File
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
|
||||
/**
|
||||
* Läser bas‑URL och API‑nyckel från BuildConfig (hålls i local.properties → buildConfigField).
|
||||
@@ -41,10 +21,10 @@ data class NoteDetailDTO(
|
||||
val lon: Double,
|
||||
val title: String,
|
||||
val body: String,
|
||||
val image: NoteImageDTO? = null, @Json(name = "created_at")
|
||||
val createdAt: Long? = null, @Json(name = "updated_at")
|
||||
val updatedAt: Long? = null, @Json(name = "username")
|
||||
val username: String? = null, @Json(name = "user_id")
|
||||
val image: NoteImageDTO? = null,
|
||||
val createdAt: Long? = null,
|
||||
val updatedAt: Long? = null,
|
||||
val username: String? = null,
|
||||
val userId: Long? = null
|
||||
)
|
||||
|
||||
@@ -62,9 +42,9 @@ data class MeResp(
|
||||
val id: Long? = null,
|
||||
val email: String? = null,
|
||||
val username: String? = null,
|
||||
@Json(name = "first_login") val firstLogin: String? = null,
|
||||
@Json(name = "last_login") val lastLogin: String? = null,
|
||||
@Json(name = "is_suspended") val isSuspended: Int? = 0
|
||||
val firstLogin: String? = null,
|
||||
val lastLogin: String? = null,
|
||||
val isSuspended: Int? = 0
|
||||
)
|
||||
|
||||
object Api {
|
||||
@@ -403,30 +383,3 @@ suspend fun fetchImageStreamPost(
|
||||
// Okänd MIME → använd generisk
|
||||
return bytes.toResponseBody("application/octet-stream".toMediaTypeOrNull())
|
||||
}
|
||||
|
||||
private data class ApiErr(
|
||||
val error: String? = null,
|
||||
val max: String? = null,
|
||||
@Json(name = "max_bytes") val maxBytes: Long? = null
|
||||
)
|
||||
|
||||
private fun extractApiErrorMessage(json: String?): String? {
|
||||
if (json.isNullOrBlank()) return null
|
||||
return try {
|
||||
// Minimal Moshi parse – filen har redan Moshi på classpath
|
||||
val moshi = Moshi.Builder().build()
|
||||
val adapter = moshi.adapter(ApiErr::class.java)
|
||||
val e = adapter.fromJson(json)
|
||||
return when {
|
||||
e?.error?.equals("file_too_large", true) == true ->
|
||||
e?.max?.let { "Bilden är för stor. Max $it." }
|
||||
?: e?.maxBytes?.let { "Bilden är för stor. Max ${it / (1024 * 1024)} MB." }
|
||||
?: "Bilden är för stor."
|
||||
!e?.error.isNullOrBlank() -> e?.error
|
||||
else -> null
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user