feat(shared): add KMP get_image.php (form stream) and delegate Android fetchImageStreamPost

This commit is contained in:
2025-09-06 19:48:36 +02:00
parent 1bfdc3f037
commit ec4d3d2746
2 changed files with 44 additions and 12 deletions

View File

@@ -556,6 +556,39 @@ object KlottrApiShared {
ok = ok, imageId = imageId, width = width, height = height, errorMessage = if (ok) null else errMsg
)
}
/**
* KMP-variant av get_image.php (form-POST med id/note/lat/lon).
* Returnerar bildbytes eller null vid fel.
*/
suspend fun getImageStreamPost(
baseUrl: String,
apiKey: String,
bearerToken: String?,
id: Long,
noteId: Long,
lat: Double,
lon: Double
): ByteArray? {
val url = ensureSlash(baseUrl) + "get_image.php"
val resp = try {
client.submitForm(
url = url,
formParameters = Parameters.build {
append("id", id.toString())
append("note", noteId.toString())
append("lat", lat.toString())
append("lon", lon.toString())
}
) {
header("X-API-Key", apiKey)
if (bearerToken != null) header(HttpHeaders.Authorization, "Bearer $bearerToken")
}
} catch (_: Throwable) {
return null
}
if (resp.status.value != 200) return null
return try { resp.body<ByteArray>() } catch (_: Throwable) { null }
}
}