Skip to content

Commit

Permalink
fix base url
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Sep 22, 2024
1 parent 1bc37f9 commit a75c2a5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package me.him188.ani.app.data.source.media.source.web

import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import io.ktor.http.URLBuilder
import kotlinx.serialization.Serializable
import me.him188.ani.app.data.source.media.source.web.format.SelectorChannelFormat
import me.him188.ani.app.data.source.media.source.web.format.SelectorChannelFormatFlattened
Expand Down Expand Up @@ -59,7 +60,24 @@ data class SelectorSearchConfig(
val matchVideo: MatchVideoConfig = MatchVideoConfig(),
) { // TODO: add Engine version capabilities
val baseUrl by lazy(LazyThreadSafetyMode.PUBLICATION) {
searchUrl.substringBeforeLast("/")
kotlin.runCatching {
URLBuilder(searchUrl).apply {
pathSegments = emptyList()
parameters.clear()
}.toString()
}.getOrElse {
val schemaIndex = searchUrl.indexOf("//")
if (schemaIndex == -1) {
searchUrl.removeSuffix("/")
} else {
val slashIndex = searchUrl.indexOf('/', startIndex = schemaIndex + 2)
if (slashIndex == -1) {
searchUrl.removeSuffix("/")
} else {
searchUrl.substring(0, slashIndex)
}
}
}
}

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,15 @@ class SelectorTestState(
null
} else {
try {
engine.searchEpisodes(
selectedSubject.subjectDetailsPageUrl,
Result.success(
engine.searchEpisodes(
selectedSubject.subjectDetailsPageUrl,
),
)
} catch (e: CancellationException) {
throw e
} catch (e: Throwable) {
Result.failure(e)
}
}
}
Expand All @@ -159,10 +163,13 @@ class SelectorTestState(
}

else -> {
convertEpisodeResult(
subjectDetailsPageDocument,
searchConfig,
queryState,
subjectDetailsPageDocument.fold(
onSuccess = { document ->
convertEpisodeResult(document, searchConfig, queryState)
},
onFailure = {
SelectorTestEpisodeListResult.UnknownError(it)
},
)
}
}
Expand Down

0 comments on commit a75c2a5

Please sign in to comment.