feat(shared): add KMP get_image.php (form stream) and delegate Android fetchImageStreamPost
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user