mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Dependency updates. OkHttp nullability changes
This commit is contained in:
		| @@ -187,12 +187,12 @@ class ChapterCache(private val context: Context) { | ||||
|             editor = diskCache.edit(key) ?: throw IOException("Unable to edit key") | ||||
|  | ||||
|             // Get OutputStream and write image 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() | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -380,7 +380,7 @@ class Downloader(private val context: Context, private val provider: DownloadPro | ||||
|                 .map { response -> | ||||
|                     val file = tmpDir.createFile("$filename.tmp") | ||||
|                     try { | ||||
|                         response.body().source().saveTo(file.openOutputStream()) | ||||
|                         response.body()!!.source().saveTo(file.openOutputStream()) | ||||
|                         val extension = getImageExtension(response, file) | ||||
|                         file.renameTo("$filename.$extension") | ||||
|                     } catch (e: Exception) { | ||||
| @@ -403,7 +403,7 @@ class Downloader(private val context: Context, private val provider: DownloadPro | ||||
|      */ | ||||
|     private fun getImageExtension(response: Response, file: UniFile): String { | ||||
|         // Read content type if available. | ||||
|         val mime = response.body().contentType()?.let { ct -> "${ct.type()}/${ct.subtype()}" } | ||||
|         val mime = response.body()?.contentType()?.let { ct -> "${ct.type()}/${ct.subtype()}" } | ||||
|             // Else guess from the uri. | ||||
|             ?: context.contentResolver.getType(file.uri) | ||||
|             // Else read magic numbers. | ||||
|   | ||||
| @@ -26,7 +26,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { | ||||
|     fun addLibManga(track: Track): Observable<Track> { | ||||
|         return rest.addLibManga(track.remote_id, track.last_chapter_read, track.toAnilistStatus()) | ||||
|                 .map { response -> | ||||
|                     response.body().close() | ||||
|                     response.body()?.close() | ||||
|                     if (!response.isSuccessful) { | ||||
|                         throw Exception("Could not add manga") | ||||
|                     } | ||||
| @@ -38,7 +38,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { | ||||
|         return rest.updateLibManga(track.remote_id, track.last_chapter_read, track.toAnilistStatus(), | ||||
|                 track.toAnilistScore()) | ||||
|                 .map { response -> | ||||
|                     response.body().close() | ||||
|                     response.body()?.close() | ||||
|                     if (!response.isSuccessful) { | ||||
|                         throw Exception("Could not update manga") | ||||
|                     } | ||||
|   | ||||
| @@ -28,7 +28,7 @@ class AnilistInterceptor(private var refreshToken: String?) : Interceptor { | ||||
|         if (oauth == null || oauth!!.isExpired()) { | ||||
|             val response = chain.proceed(AnilistApi.refreshTokenRequest(refreshToken!!)) | ||||
|             oauth = if (response.isSuccessful) { | ||||
|                 Gson().fromJson(response.body().string(), OAuth::class.java) | ||||
|                 Gson().fromJson(response.body()!!.string(), OAuth::class.java) | ||||
|             } else { | ||||
|                 response.close() | ||||
|                 null | ||||
|   | ||||
| @@ -22,7 +22,7 @@ class KitsuInterceptor(val kitsu: Kitsu, val gson: Gson) : Interceptor { | ||||
|         if (currAuth.isExpired()) { | ||||
|             val response = chain.proceed(KitsuApi.refreshTokenRequest(refreshToken)) | ||||
|             if (response.isSuccessful) { | ||||
|                 newAuth(gson.fromJson(response.body().string(), OAuth::class.java)) | ||||
|                 newAuth(gson.fromJson(response.body()!!.string(), OAuth::class.java)) | ||||
|             } else { | ||||
|                 response.close() | ||||
|             } | ||||
|   | ||||
| @@ -46,7 +46,7 @@ class MyanimelistApi(private val client: OkHttpClient, username: String, passwor | ||||
|         } else { | ||||
|             client.newCall(GET(getSearchUrl(query), headers)) | ||||
|                     .asObservable() | ||||
|                     .map { Jsoup.parse(it.body().string()) } | ||||
|                     .map { Jsoup.parse(it.body()!!.string()) } | ||||
|                     .flatMap { Observable.from(it.select("entry")) } | ||||
|                     .filter { it.select("type").text() != "Novel" } | ||||
|                     .map { | ||||
| @@ -64,7 +64,7 @@ class MyanimelistApi(private val client: OkHttpClient, username: String, passwor | ||||
|         return client | ||||
|                 .newCall(GET(getListUrl(username), headers)) | ||||
|                 .asObservable() | ||||
|                 .map { Jsoup.parse(it.body().string()) } | ||||
|                 .map { Jsoup.parse(it.body()!!.string()) } | ||||
|                 .flatMap { Observable.from(it.select("manga")) } | ||||
|                 .map { | ||||
|                     Track.create(TrackManager.MYANIMELIST).apply { | ||||
|   | ||||
| @@ -86,7 +86,7 @@ class UpdateDownloaderService : IntentService(UpdateDownloaderService::class.jav | ||||
|             val apkFile = File(externalCacheDir, "update.apk") | ||||
|  | ||||
|             if (response.isSuccessful) { | ||||
|                 response.body().source().saveTo(apkFile) | ||||
|                 response.body()!!.source().saveTo(apkFile) | ||||
|             } else { | ||||
|                 response.close() | ||||
|                 throw Exception("Unsuccessful response") | ||||
|   | ||||
| @@ -8,13 +8,10 @@ import okhttp3.Response | ||||
|  | ||||
| class CloudflareInterceptor : Interceptor { | ||||
|  | ||||
|     //language=RegExp | ||||
|     private val operationPattern = Regex("""setTimeout\(function\(\)\{\s+(var (?:\w,)+f.+?\r?\n[\s\S]+?a\.value =.+?)\r?\n""") | ||||
|      | ||||
|     //language=RegExp | ||||
|     private val passPattern = Regex("""name="pass" value="(.+?)"""") | ||||
|  | ||||
|     //language=RegExp | ||||
|     private val challengePattern = Regex("""name="jschl_vc" value="(\w+)"""") | ||||
|  | ||||
|     @Synchronized | ||||
| @@ -34,7 +31,7 @@ class CloudflareInterceptor : Interceptor { | ||||
|             val originalRequest = response.request() | ||||
|             val url = originalRequest.url() | ||||
|             val domain = url.host() | ||||
|             val content = response.body().string() | ||||
|             val content = response.body()!!.string() | ||||
|  | ||||
|             // CloudFlare requires waiting 4 seconds before resolving the challenge | ||||
|             Thread.sleep(4000) | ||||
| @@ -48,9 +45,7 @@ class CloudflareInterceptor : Interceptor { | ||||
|             } | ||||
|  | ||||
|             val js = operation | ||||
|                     //language=RegExp | ||||
|                     .replace(Regex("""a\.value =(.+?) \+.*"""), "$1") | ||||
|                     //language=RegExp | ||||
|                     .replace(Regex("""\s{3,}[a-z](?: = |\.).+"""), "") | ||||
|                     .replace("\n", "") | ||||
|  | ||||
| @@ -58,7 +53,7 @@ class CloudflareInterceptor : Interceptor { | ||||
|  | ||||
|             val answer = "${result + domain.length}" | ||||
|  | ||||
|             val cloudflareUrl = HttpUrl.parse("${url.scheme()}://$domain/cdn-cgi/l/chk_jschl") | ||||
|             val cloudflareUrl = HttpUrl.parse("${url.scheme()}://$domain/cdn-cgi/l/chk_jschl")!! | ||||
|                     .newBuilder() | ||||
|                     .addQueryParameter("jschl_vc", challenge) | ||||
|                     .addQueryParameter("pass", pass) | ||||
|   | ||||
| @@ -61,7 +61,7 @@ fun OkHttpClient.newCallWithProgress(request: Request, listener: ProgressListene | ||||
|             .addNetworkInterceptor { chain -> | ||||
|                 val originalResponse = chain.proceed(chain.request()) | ||||
|                 originalResponse.newBuilder() | ||||
|                         .body(ProgressResponseBody(originalResponse.body(), listener)) | ||||
|                         .body(ProgressResponseBody(originalResponse.body()!!, listener)) | ||||
|                         .build() | ||||
|             } | ||||
|             .build() | ||||
|   | ||||
| @@ -18,7 +18,7 @@ class PersistentCookieStore(context: Context) { | ||||
|             if (cookies != null) { | ||||
|                 try { | ||||
|                     val url = HttpUrl.parse("http://$key") | ||||
|                     val nonExpiredCookies = cookies.map { Cookie.parse(url, it) } | ||||
|                     val nonExpiredCookies = cookies.mapNotNull { Cookie.parse(url, it) } | ||||
|                             .filter { !it.hasExpired() } | ||||
|                     cookieMap.put(key, nonExpiredCookies) | ||||
|                 } catch (e: Exception) { | ||||
|   | ||||
| @@ -12,7 +12,7 @@ class ProgressResponseBody(private val responseBody: ResponseBody, private val p | ||||
|     } | ||||
|  | ||||
|     override fun contentType(): MediaType { | ||||
|         return responseBody.contentType() | ||||
|         return responseBody.contentType()!! | ||||
|     } | ||||
|  | ||||
|     override fun contentLength(): Long { | ||||
|   | ||||
| @@ -171,7 +171,7 @@ class YamlHttpSource(mappings: Map<*, *>) : HttpSource() { | ||||
|     } | ||||
|  | ||||
|     override fun pageListParse(response: Response): List<Page> { | ||||
|         val body = response.body().string() | ||||
|         val body = response.body()!!.string() | ||||
|         val url = response.request().url().toString() | ||||
|  | ||||
|         val pages = mutableListOf<Page>() | ||||
| @@ -216,7 +216,7 @@ class YamlHttpSource(mappings: Map<*, *>) : HttpSource() { | ||||
|     } | ||||
|  | ||||
|     override fun imageUrlParse(response: Response): String { | ||||
|         val body = response.body().string() | ||||
|         val body = response.body()!!.string() | ||||
|         val url = response.request().url().toString() | ||||
|  | ||||
|         with(map.pages) { | ||||
|   | ||||
| @@ -85,7 +85,7 @@ class Batoto : ParsedHttpSource(), LoginSource { | ||||
|     override fun latestUpdatesNextPageSelector() = "#show_more_row" | ||||
|  | ||||
|     override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { | ||||
|         val url = HttpUrl.parse("$baseUrl/search_ajax").newBuilder() | ||||
|         val url = HttpUrl.parse("$baseUrl/search_ajax")!!.newBuilder() | ||||
|         if (!query.isEmpty()) url.addQueryParameter("name", query).addQueryParameter("name_cond", "c") | ||||
|         var genres = "" | ||||
|         filters.forEach { filter -> | ||||
| @@ -162,7 +162,7 @@ class Batoto : ParsedHttpSource(), LoginSource { | ||||
|     } | ||||
|  | ||||
|     override fun chapterListParse(response: Response): List<SChapter> { | ||||
|         val body = response.body().string() | ||||
|         val body = response.body()!!.string() | ||||
|         val matcher = staffNotice.matcher(body) | ||||
|         if (matcher.find()) { | ||||
|             @Suppress("DEPRECATION") | ||||
| @@ -271,7 +271,7 @@ class Batoto : ParsedHttpSource(), LoginSource { | ||||
|     } | ||||
|  | ||||
|     override fun isAuthenticationSuccessful(response: Response) = | ||||
|             response.priorResponse() != null && response.priorResponse().code() == 302 | ||||
|             response.priorResponse() != null && response.priorResponse()!!.code() == 302 | ||||
|  | ||||
|     override fun isLogged(): Boolean { | ||||
|         return network.cookies.get(URI(baseUrl)).any { it.name() == "pass_hash" } | ||||
|   | ||||
| @@ -115,13 +115,13 @@ class Kissmanga : ParsedHttpSource() { | ||||
|     override fun pageListRequest(chapter: SChapter) = POST(baseUrl + chapter.url, headers) | ||||
|  | ||||
|     override fun pageListParse(response: Response): List<Page> { | ||||
|         val body = response.body().string() | ||||
|         val body = response.body()!!.string() | ||||
|  | ||||
|         val pages = mutableListOf<Page>() | ||||
|  | ||||
|         // Kissmanga now encrypts the urls, so we need to execute these two scripts in JS. | ||||
|         val ca = client.newCall(GET("$baseUrl/Scripts/ca.js", headers)).execute().body().string() | ||||
|         val lo = client.newCall(GET("$baseUrl/Scripts/lo.js", headers)).execute().body().string() | ||||
|         val ca = client.newCall(GET("$baseUrl/Scripts/ca.js", headers)).execute().body()!!.string() | ||||
|         val lo = client.newCall(GET("$baseUrl/Scripts/lo.js", headers)).execute().body()!!.string() | ||||
|  | ||||
|         Duktape.create().use { | ||||
|             it.evaluate(ca) | ||||
|   | ||||
| @@ -55,7 +55,7 @@ class Mangafox : ParsedHttpSource() { | ||||
|     override fun latestUpdatesNextPageSelector() = "a:has(span.next)" | ||||
|  | ||||
|     override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { | ||||
|         val url = HttpUrl.parse("$baseUrl/search.php?name_method=cw&author_method=cw&artist_method=cw&advopts=1").newBuilder().addQueryParameter("name", query) | ||||
|         val url = HttpUrl.parse("$baseUrl/search.php?name_method=cw&author_method=cw&artist_method=cw&advopts=1")!!.newBuilder().addQueryParameter("name", query) | ||||
|         (if (filters.isEmpty()) getFilterList() else filters).forEach { filter -> | ||||
|             when (filter) { | ||||
|                 is Status -> url.addQueryParameter(filter.id, filter.state.toString()) | ||||
|   | ||||
| @@ -57,7 +57,7 @@ class Mangahere : ParsedHttpSource() { | ||||
|     override fun latestUpdatesNextPageSelector() = "div.next-page > a.next" | ||||
|  | ||||
|     override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { | ||||
|         val url = HttpUrl.parse("$baseUrl/search.php?name_method=cw&author_method=cw&artist_method=cw&advopts=1").newBuilder().addQueryParameter("name", query) | ||||
|         val url = HttpUrl.parse("$baseUrl/search.php?name_method=cw&author_method=cw&artist_method=cw&advopts=1")!!.newBuilder().addQueryParameter("name", query) | ||||
|         (if (filters.isEmpty()) getFilterList() else filters).forEach { filter -> | ||||
|             when (filter) { | ||||
|                 is Status -> url.addQueryParameter("is_completed", arrayOf("", "1", "0")[filter.state]) | ||||
|   | ||||
| @@ -54,7 +54,7 @@ class Mangasee : ParsedHttpSource() { | ||||
|     override fun searchMangaSelector() = "div.requested > div.row" | ||||
|  | ||||
|     override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { | ||||
|         val url = HttpUrl.parse("$baseUrl/search/request.php").newBuilder() | ||||
|         val url = HttpUrl.parse("$baseUrl/search/request.php")!!.newBuilder() | ||||
|         if (!query.isEmpty()) url.addQueryParameter("keyword", query) | ||||
|         val genres = mutableListOf<String>() | ||||
|         val genresNo = mutableListOf<String>() | ||||
| @@ -84,7 +84,7 @@ class Mangasee : ParsedHttpSource() { | ||||
|     } | ||||
|  | ||||
|     private fun convertQueryToPost(page: Int, url: String): Pair<FormBody.Builder, String> { | ||||
|         val url = HttpUrl.parse(url) | ||||
|         val url = HttpUrl.parse(url)!! | ||||
|         val body = FormBody.Builder().add("page", page.toString()) | ||||
|         for (i in 0..url.querySize() - 1) { | ||||
|             body.add(url.queryParameterName(i), url.queryParameterValue(i)) | ||||
|   | ||||
| @@ -152,7 +152,7 @@ class Mangachan : ParsedHttpSource() { | ||||
|     } | ||||
|  | ||||
|     override fun pageListParse(response: Response): List<Page> { | ||||
|         val html = response.body().string() | ||||
|         val html = response.body()!!.string() | ||||
|         val beginIndex = html.indexOf("fullimg\":[") + 10 | ||||
|         val endIndex = html.indexOf(",]", beginIndex) | ||||
|         val trimmedHtml = html.substring(beginIndex, endIndex).replace("\"", "") | ||||
|   | ||||
| @@ -120,7 +120,7 @@ class Mintmanga : ParsedHttpSource() { | ||||
|     } | ||||
|  | ||||
|     override fun pageListParse(response: Response): List<Page> { | ||||
|         val html = response.body().string() | ||||
|         val html = response.body()!!.string() | ||||
|         val beginIndex = html.indexOf("rm_h.init( [") | ||||
|         val endIndex = html.indexOf("], 0, false);", beginIndex) | ||||
|         val trimmedHtml = html.substring(beginIndex, endIndex) | ||||
|   | ||||
| @@ -120,7 +120,7 @@ class Readmanga : ParsedHttpSource() { | ||||
|     } | ||||
|  | ||||
|     override fun pageListParse(response: Response): List<Page> { | ||||
|         val html = response.body().string() | ||||
|         val html = response.body()!!.string() | ||||
|         val beginIndex = html.indexOf("rm_h.init( [") | ||||
|         val endIndex = html.indexOf("], 0, false);", beginIndex) | ||||
|         val trimmedHtml = html.substring(beginIndex, endIndex) | ||||
|   | ||||
| @@ -22,5 +22,5 @@ fun Element.attrOrText(css: String): String { | ||||
|  * @param html the body of the response. Use only if the body was read before calling this method. | ||||
|  */ | ||||
| fun Response.asJsoup(html: String? = null): Document { | ||||
|     return Jsoup.parse(html ?: body().string(), request().url().toString()) | ||||
|     return Jsoup.parse(html ?: body()!!.string(), request().url().toString()) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user