URL encode Kitsu search queries (fixes #5712)
This commit is contained in:
parent
3435636ca0
commit
d04d676d2f
3 changed files with 8 additions and 4 deletions
|
@ -24,6 +24,7 @@ import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.net.URLEncoder
|
import java.net.URLEncoder
|
||||||
|
import java.nio.charset.StandardCharsets
|
||||||
|
|
||||||
class BangumiApi(private val client: OkHttpClient, interceptor: BangumiInterceptor) {
|
class BangumiApi(private val client: OkHttpClient, interceptor: BangumiInterceptor) {
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ class BangumiApi(private val client: OkHttpClient, interceptor: BangumiIntercept
|
||||||
|
|
||||||
suspend fun search(search: String): List<TrackSearch> {
|
suspend fun search(search: String): List<TrackSearch> {
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val url = "$apiUrl/search/subject/${URLEncoder.encode(search, Charsets.UTF_8.name())}"
|
val url = "$apiUrl/search/subject/${URLEncoder.encode(search, StandardCharsets.UTF_8.name())}"
|
||||||
.toUri()
|
.toUri()
|
||||||
.buildUpon()
|
.buildUpon()
|
||||||
.appendQueryParameter("max_results", "20")
|
.appendQueryParameter("max_results", "20")
|
||||||
|
|
|
@ -24,6 +24,8 @@ import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
|
import java.net.URLEncoder
|
||||||
|
import java.nio.charset.StandardCharsets
|
||||||
|
|
||||||
class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) {
|
class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) {
|
||||||
|
|
||||||
|
@ -125,7 +127,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
|
||||||
private suspend fun algoliaSearch(key: String, query: String): List<TrackSearch> {
|
private suspend fun algoliaSearch(key: String, query: String): List<TrackSearch> {
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val jsonObject = buildJsonObject {
|
val jsonObject = buildJsonObject {
|
||||||
put("params", "query=$query$algoliaFilter")
|
put("params", "query=${URLEncoder.encode(query, StandardCharsets.UTF_8.name())}$algoliaFilter")
|
||||||
}
|
}
|
||||||
|
|
||||||
client.newCall(
|
client.newCall(
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.kanade.tachiyomi.util.lang
|
package eu.kanade.tachiyomi.util.lang
|
||||||
|
|
||||||
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator
|
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator
|
||||||
|
import java.nio.charset.StandardCharsets
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,7 +42,7 @@ fun String.compareToCaseInsensitiveNaturalOrder(other: String): Int {
|
||||||
* Returns the size of the string as the number of bytes.
|
* Returns the size of the string as the number of bytes.
|
||||||
*/
|
*/
|
||||||
fun String.byteSize(): Int {
|
fun String.byteSize(): Int {
|
||||||
return toByteArray(Charsets.UTF_8).size
|
return toByteArray(StandardCharsets.UTF_8).size
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +50,7 @@ fun String.byteSize(): Int {
|
||||||
* string is shorter.
|
* string is shorter.
|
||||||
*/
|
*/
|
||||||
fun String.takeBytes(n: Int): String {
|
fun String.takeBytes(n: Int): String {
|
||||||
val bytes = toByteArray(Charsets.UTF_8)
|
val bytes = toByteArray(StandardCharsets.UTF_8)
|
||||||
return if (bytes.size <= n) {
|
return if (bytes.size <= n) {
|
||||||
this
|
this
|
||||||
} else {
|
} else {
|
||||||
|
|
Reference in a new issue