Address some OkHttp nullability issues
This commit is contained in:
parent
0c1ac913cb
commit
6e1e42fefd
@ -169,12 +169,12 @@ class PagePreviewCache(private val context: Context) {
|
||||
editor = diskCache.edit(key) ?: throw IOException("Unable to edit key")
|
||||
|
||||
// Get OutputStream and write page with Okio.
|
||||
response.body!!.source().saveTo(editor.newOutputStream(0))
|
||||
response.body.source().saveTo(editor.newOutputStream(0))
|
||||
|
||||
diskCache.flush()
|
||||
editor.commit()
|
||||
} finally {
|
||||
response.body?.close()
|
||||
response.body.close()
|
||||
editor?.abortUnlessCommitted()
|
||||
}
|
||||
}
|
||||
|
@ -1087,7 +1087,7 @@ class EHentai(
|
||||
.url(EH_API_BASE)
|
||||
.post(json.toString().toRequestBody(JSON))
|
||||
.build(),
|
||||
).execute().body!!.string(),
|
||||
).execute().body.string(),
|
||||
)
|
||||
|
||||
val obj = outJson["tokenlist"]!!.jsonArray.first().jsonObject
|
||||
@ -1216,7 +1216,7 @@ class EHentai(
|
||||
if (response.isSuccessful) {
|
||||
val body = ByteArrayOutputStream()
|
||||
.use {
|
||||
val bitmap = BitmapFactory.decodeStream(response.body!!.byteStream())
|
||||
val bitmap = BitmapFactory.decodeStream(response.body.byteStream())
|
||||
?: throw IOException("Null bitmap($thumbnailPreview)")
|
||||
Bitmap.createBitmap(
|
||||
bitmap,
|
||||
|
@ -62,7 +62,7 @@ class NHentai(delegate: HttpSource, val context: Context) :
|
||||
}
|
||||
|
||||
override suspend fun parseIntoMetadata(metadata: NHentaiSearchMetadata, input: Response) {
|
||||
val json = GALLERY_JSON_REGEX.find(input.body?.string().orEmpty())!!.groupValues[1].replace(
|
||||
val json = GALLERY_JSON_REGEX.find(input.body.string())!!.groupValues[1].replace(
|
||||
UNICODE_ESCAPE_REGEX,
|
||||
) { it.groupValues[1].toInt(radix = 16).toChar().toString() }
|
||||
val jsonResponse = jsonParser.decodeFromString<JsonResponse>(json)
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user