feat(shared): add KMP get_image.php (form stream) and delegate Android fetchImageStreamPost
This commit is contained in:
@@ -13,6 +13,7 @@ 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
|
||||
@@ -514,33 +515,31 @@ suspend fun setUsernameRemote(input: String): UsernameSetResp? {
|
||||
return sh
|
||||
}
|
||||
|
||||
|
||||
/** Hjälpfunktion för att hämta en bildström via POST (form-POST till PHP). */
|
||||
/** Hämta bildström via delad KMP-klient (form-POST) och bygg ResponseBody */
|
||||
suspend fun fetchImageStreamPost(
|
||||
imageId: Long,
|
||||
noteId: Long,
|
||||
lat: Double,
|
||||
lon: Double
|
||||
): ResponseBody? {
|
||||
return try {
|
||||
val resp = Api.svc.getImagePost(
|
||||
val bytes = try {
|
||||
KlottrApiShared.getImageStreamPost(
|
||||
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
||||
apiKey = ApiConfig.SERVER_API_KEY,
|
||||
bearerToken = app.klottr.util.Auth.idToken,
|
||||
id = imageId,
|
||||
noteId = noteId,
|
||||
lat = lat,
|
||||
lon = lon
|
||||
)
|
||||
if (resp.isSuccessful) {
|
||||
resp.body()
|
||||
} else {
|
||||
app.klottr.util.AppLog.d { "get_image FAIL code=${resp.code()} err=${resp.errorBody()?.string()}" }
|
||||
null
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
app.klottr.util.AppLog.d { "get_image exception: ${t.message}" }
|
||||
null
|
||||
}
|
||||
}
|
||||
} ?: return null
|
||||
|
||||
// Okänd MIME → använd generisk
|
||||
return bytes.toResponseBody("application/octet-stream".toMediaTypeOrNull())
|
||||
}
|
||||
|
||||
private data class ApiErr(
|
||||
val error: String? = null,
|
||||
|
||||
Reference in New Issue
Block a user