Skip to content

Commit

Permalink
[commonize] #496 Commonize :data-source:bangumi
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Jul 28, 2024
1 parent 0962442 commit d0c0a3f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 72 deletions.
3 changes: 1 addition & 2 deletions data-sources/bangumi/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
idea
`flatten-source-sets`
`ani-lib-targets`
`ani-mpp-lib-targets`
id("org.openapi.generator") version "7.6.0"
}

Expand Down
20 changes: 7 additions & 13 deletions data-sources/bangumi/src/commonMain/kotlin/BangumiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@ import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpStatusCode
import io.ktor.http.appendPathSegments
import io.ktor.http.contentType
import io.ktor.http.isSuccess
import io.ktor.serialization.kotlinx.json.json
import io.ktor.utils.io.core.Closeable
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
Expand All @@ -66,9 +65,6 @@ import me.him188.ani.datasources.bangumi.next.apis.SubjectBangumiNextApi
import me.him188.ani.utils.ktor.registerLogging
import me.him188.ani.utils.logging.logger
import me.him188.ani.utils.serialization.toJsonArray
import java.net.URLEncoder
import java.nio.charset.StandardCharsets
import java.util.Objects
import kotlin.coroutines.CoroutineContext

interface BangumiClient : Closeable {
Expand Down Expand Up @@ -346,16 +342,14 @@ internal class BangumiClientImpl(
start: Int?,
maxResults: Int?
): Paged<BangumiLegacySubject> {
val keywordCoded = withContext(Dispatchers.IO) {
URLEncoder.encode(keyword, StandardCharsets.UTF_8.name())
}
val resp = httpClient.get("$BANGUMI_API_HOST/search/subject".plus("/").plus(keywordCoded)) {
val resp = httpClient.get("$BANGUMI_API_HOST/search/subject".plus("/")) {
url {
appendPathSegments(keyword)
}
parameter("type", type.value)
parameter("responseGroup", responseGroup?.toString())
if (Objects.nonNull(start)) {
parameter("start", start)
}
if (Objects.nonNull(maxResults)) parameter("max_results", maxResults)
parameter("start", start)
parameter("max_results", maxResults)
}

if (!resp.status.isSuccess()) {
Expand Down
56 changes: 0 additions & 56 deletions data-sources/bangumi/src/commonMain/kotlin/processing/Episodes.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fun Float.fixToString(length: Int, prefix: Char = '0'): String {
}

fun String.fixToString(length: Int, prefix: Char): String {
val str = this.toString()
val str = this
return if (str.length >= length) {
str
} else {
Expand Down

0 comments on commit d0c0a3f

Please sign in to comment.