Skip to content

Commit

Permalink
KitsuApi.kt: Sanitize URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Caio99BR committed Jul 2, 2024
1 parent 0bd6a93 commit ec6ce93
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
with(json) {
authClient.newCall(
POST(
"${BASE_URL}library-entries",
LIBRARY_URL,
headers = headersOf(
"Content-Type",
"application/vnd.api+json",
Expand Down Expand Up @@ -104,7 +104,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
with(json) {
authClient.newCall(
Request.Builder()
.url("${BASE_URL}library-entries/${track.remote_id}")
.url("${LIBRARY_URL}/${track.remote_id}")
.headers(
headersOf(
"Content-Type",
Expand All @@ -130,7 +130,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
authClient
.newCall(
DELETE(
"${BASE_URL}library-entries/${track.remoteId}",
"${LIBRARY_URL}/${track.remoteId}",
headers = headersOf(
"Content-Type",
"application/vnd.api+json",
Expand All @@ -143,7 +143,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
suspend fun search(query: String): List<TrackSearch> {
return withIOContext {
with(json) {
authClient.newCall(GET(ALGOLIA_KEY_URL))
authClient.newCall(GET(BASE_ALGOLIA_KEY_URL))
.awaitSuccess()
.parseAs<JsonObject>()
.let {
Expand All @@ -163,7 +163,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
with(json) {
client.newCall(
POST(
ALGOLIA_URL,
BASE_ALGOLIA_URL,
headers = headersOf(
"X-Algolia-Application-Id",
ALGOLIA_APP_ID,
Expand All @@ -177,17 +177,17 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
.parseAs<JsonObject>()
.let {
it["hits"]!!.jsonArray
.map { KitsuSearchManga(it.jsonObject) }
.filter { it.subType != "novel" }
.map { it.toTrack() }
.map { it -> KitsuSearchManga(it.jsonObject) }
.filter { it -> it.subType != "novel" }
.map { it -> it.toTrack() }
}
}
}
}

suspend fun findLibManga(track: Track, userId: String): Track? {
return withIOContext {
val url = "${BASE_URL}library-entries".toUri().buildUpon()
val url = LIBRARY_URL.toUri().buildUpon()
.encodedQuery("filter[manga_id]=${track.remote_id}&filter[user_id]=$userId")
.appendQueryParameter("include", "manga")
.build()
Expand All @@ -210,7 +210,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)

suspend fun getLibManga(track: Track): Track {
return withIOContext {
val url = "${BASE_URL}library-entries".toUri().buildUpon()
val url = LIBRARY_URL.toUri().buildUpon()
.encodedQuery("filter[id]=${track.remote_id}")
.appendQueryParameter("include", "manga")
.build()
Expand Down Expand Up @@ -250,7 +250,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)

suspend fun getCurrentUser(): String {
return withIOContext {
val url = "${BASE_URL}users".toUri().buildUpon()
val url = USERS_URL.toUri().buildUpon()
.encodedQuery("filter[self]=true")
.build()
with(json) {
Expand All @@ -270,12 +270,14 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
private const val CLIENT_SECRET =
"54d7307928f63414defd96399fc31ba847961ceaecef3a5fd93144e960c0e151"

private const val BASE_URL = "https://kitsu.io/api/edge/"
private const val LOGIN_URL = "https://kitsu.io/api/oauth/token"
private const val BASE_MANGA_URL = "https://kitsu.io/manga/"
private const val ALGOLIA_KEY_URL = "https://kitsu.io/api/edge/algolia-keys/media/"
private const val BASE_URL = "https://kitsu.io"
private const val LIBRARY_URL = "${BASE_URL}/api/edge/library-entries"
private const val USERS_URL = "${BASE_URL}/api/edge/users"
private const val LOGIN_URL = "${BASE_URL}/api/oauth/token"
private const val BASE_MANGA_URL = "${BASE_URL}/manga/"
private const val BASE_ALGOLIA_KEY_URL = "${BASE_URL}/api/edge/algolia-keys/media/"

private const val ALGOLIA_URL =
private const val BASE_ALGOLIA_URL =
"https://AWQO5J657S-dsn.algolia.net/1/indexes/production_media/query/"
private const val ALGOLIA_APP_ID = "AWQO5J657S"
private const val ALGOLIA_FILTER =
Expand Down

0 comments on commit ec6ce93

Please sign in to comment.