Skip to content

Commit ec6ce93

Browse files
committed
KitsuApi.kt: Sanitize URLs
1 parent 0bd6a93 commit ec6ce93

File tree

1 file changed

+18
-16
lines changed
  • app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu

1 file changed

+18
-16
lines changed

app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt

+18-16
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
6666
with(json) {
6767
authClient.newCall(
6868
POST(
69-
"${BASE_URL}library-entries",
69+
LIBRARY_URL,
7070
headers = headersOf(
7171
"Content-Type",
7272
"application/vnd.api+json",
@@ -104,7 +104,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
104104
with(json) {
105105
authClient.newCall(
106106
Request.Builder()
107-
.url("${BASE_URL}library-entries/${track.remote_id}")
107+
.url("${LIBRARY_URL}/${track.remote_id}")
108108
.headers(
109109
headersOf(
110110
"Content-Type",
@@ -130,7 +130,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
130130
authClient
131131
.newCall(
132132
DELETE(
133-
"${BASE_URL}library-entries/${track.remoteId}",
133+
"${LIBRARY_URL}/${track.remoteId}",
134134
headers = headersOf(
135135
"Content-Type",
136136
"application/vnd.api+json",
@@ -143,7 +143,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
143143
suspend fun search(query: String): List<TrackSearch> {
144144
return withIOContext {
145145
with(json) {
146-
authClient.newCall(GET(ALGOLIA_KEY_URL))
146+
authClient.newCall(GET(BASE_ALGOLIA_KEY_URL))
147147
.awaitSuccess()
148148
.parseAs<JsonObject>()
149149
.let {
@@ -163,7 +163,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
163163
with(json) {
164164
client.newCall(
165165
POST(
166-
ALGOLIA_URL,
166+
BASE_ALGOLIA_URL,
167167
headers = headersOf(
168168
"X-Algolia-Application-Id",
169169
ALGOLIA_APP_ID,
@@ -177,17 +177,17 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
177177
.parseAs<JsonObject>()
178178
.let {
179179
it["hits"]!!.jsonArray
180-
.map { KitsuSearchManga(it.jsonObject) }
181-
.filter { it.subType != "novel" }
182-
.map { it.toTrack() }
180+
.map { it -> KitsuSearchManga(it.jsonObject) }
181+
.filter { it -> it.subType != "novel" }
182+
.map { it -> it.toTrack() }
183183
}
184184
}
185185
}
186186
}
187187

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

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

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

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

278-
private const val ALGOLIA_URL =
280+
private const val BASE_ALGOLIA_URL =
279281
"https://AWQO5J657S-dsn.algolia.net/1/indexes/production_media/query/"
280282
private const val ALGOLIA_APP_ID = "AWQO5J657S"
281283
private const val ALGOLIA_FILTER =

0 commit comments

Comments
 (0)