Address some OkHttp nullability issues
This commit is contained in:
@@ -32,7 +32,7 @@ class AzukiHandler(currentClient: OkHttpClient, userAgent: String) {
|
||||
}
|
||||
|
||||
fun pageListParse(response: Response): List<Page> {
|
||||
return Json.parseToJsonElement(response.body!!.string())
|
||||
return Json.parseToJsonElement(response.body.string())
|
||||
.jsonObject["pages"]!!
|
||||
.jsonArray.mapIndexed { index, element ->
|
||||
val url = element.jsonObject["image_wm"]!!.jsonObject["webp"]!!.jsonArray[1].jsonObject["url"]!!.jsonPrimitive.content
|
||||
|
||||
@@ -45,7 +45,7 @@ class ComikeyHandler(cloudflareClient: OkHttpClient, userAgent: String) {
|
||||
}
|
||||
|
||||
private fun getActualPageList(response: Response): Request? {
|
||||
val element = Json.parseToJsonElement(response.body!!.string()).jsonObject
|
||||
val element = Json.parseToJsonElement(response.body.string()).jsonObject
|
||||
val ok = element["ok"]?.jsonPrimitive?.booleanOrNull ?: false
|
||||
if (ok.not()) {
|
||||
return null
|
||||
@@ -55,7 +55,7 @@ class ComikeyHandler(cloudflareClient: OkHttpClient, userAgent: String) {
|
||||
}
|
||||
|
||||
fun pageListParse(response: Response): List<Page> {
|
||||
return Json.parseToJsonElement(response.body!!.string())
|
||||
return Json.parseToJsonElement(response.body.string())
|
||||
.jsonObject["readingOrder"]!!
|
||||
.jsonArray.mapIndexed { index, element ->
|
||||
val url = element.jsonObject["href"]!!.jsonPrimitive.content
|
||||
|
||||
@@ -26,7 +26,7 @@ class MangaHotHandler(currentClient: OkHttpClient, userAgent: String) {
|
||||
}
|
||||
|
||||
fun pageListParse(response: Response): List<Page> {
|
||||
return Json.parseToJsonElement(response.body!!.string())
|
||||
return Json.parseToJsonElement(response.body.string())
|
||||
.jsonObject["content"]!!.jsonObject["contentUrls"]!!
|
||||
.jsonArray.mapIndexed { index, element ->
|
||||
val url = element.jsonPrimitive.content
|
||||
|
||||
@@ -40,7 +40,7 @@ class MangaPlusHandler(currentClient: OkHttpClient) {
|
||||
}
|
||||
|
||||
private fun pageListParse(response: Response): List<Page> {
|
||||
val result = ProtoBuf.decodeFromByteArray<MangaPlusResponse>(response.body!!.bytes())
|
||||
val result = ProtoBuf.decodeFromByteArray<MangaPlusResponse>(response.body.bytes())
|
||||
|
||||
if (result.success == null) {
|
||||
throw Exception("error getting images")
|
||||
@@ -70,7 +70,7 @@ class MangaPlusHandler(currentClient: OkHttpClient) {
|
||||
|
||||
val response = chain.proceed(request)
|
||||
|
||||
val image = decodeImage(encryptionKey, response.body!!.bytes())
|
||||
val image = decodeImage(encryptionKey, response.body.bytes())
|
||||
|
||||
val body = image.toResponseBody("image/jpeg".toMediaTypeOrNull())
|
||||
return response.newBuilder().body(body).build()
|
||||
|
||||
@@ -52,7 +52,7 @@ class MyAnimeList : API("https://api.jikan.moe/v3/") {
|
||||
.toString()
|
||||
|
||||
val response = client.newCall(GET(apiUrl)).await()
|
||||
val body = withIOContext { response.body?.string() } ?: throw Exception("Null Response")
|
||||
val body = withIOContext { response.body.string() }
|
||||
val data = Json.decodeFromString<JsonObject>(body)
|
||||
val recommendations = data["recommendations"] as? JsonArray
|
||||
return recommendations?.filterIsInstance<JsonObject>()?.map { rec ->
|
||||
|
||||
@@ -292,7 +292,7 @@ class BrowserActionActivity : AppCompatActivity() {
|
||||
token to it
|
||||
}
|
||||
}.flatMap { (token, response) ->
|
||||
val audioFile = response.body!!.bytes()
|
||||
val audioFile = response.body.bytes()
|
||||
|
||||
httpClient.newCall(
|
||||
Request.Builder()
|
||||
|
||||
@@ -7,8 +7,7 @@ import okhttp3.ResponseBody.Companion.toResponseBody
|
||||
import org.jsoup.nodes.Document
|
||||
|
||||
fun Response.interceptAsHtml(block: (Document) -> Unit): Response {
|
||||
val body = body
|
||||
return if (body?.contentType()?.type == "text" &&
|
||||
return if (body.contentType()?.type == "text" &&
|
||||
body.contentType()?.subtype == "html"
|
||||
) {
|
||||
val bodyString = body.string()
|
||||
|
||||
Reference in New Issue
Block a user