-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[commonize] #496 Commonize
:data-sources:api
and ktor
- Loading branch information
Showing
44 changed files
with
164 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package me.him188.ani.datasources.api | ||
|
||
import me.him188.ani.datasources.api.EpisodeSort.Special | ||
import java.math.BigDecimal | ||
|
||
fun EpisodeSort(int: BigDecimal): EpisodeSort { | ||
if (int < BigDecimal.ZERO) return Special(int.toString()) | ||
return EpisodeSort(int.toString()) | ||
} |
42 changes: 42 additions & 0 deletions
42
data-sources/api/src/jvmMain/kotlin/source/HttpMediaSource.jvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package me.him188.ani.datasources.api.source | ||
|
||
import io.ktor.client.call.body | ||
import io.ktor.client.statement.HttpResponse | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.content.OutgoingContent | ||
import io.ktor.serialization.ContentConverter | ||
import io.ktor.util.reflect.TypeInfo | ||
import io.ktor.utils.io.ByteReadChannel | ||
import io.ktor.utils.io.charsets.decode | ||
import io.ktor.utils.io.jvm.javaio.toInputStream | ||
import io.ktor.utils.io.streams.asInput | ||
import org.jsoup.Jsoup | ||
import org.jsoup.nodes.Document | ||
import java.nio.charset.Charset | ||
|
||
suspend inline fun HttpResponse.bodyAsDocument(): Document = body() | ||
|
||
internal actual fun getXmlConverter(): ContentConverter = XmlConverter | ||
|
||
private object XmlConverter : ContentConverter { | ||
override suspend fun deserialize( | ||
charset: Charset, | ||
typeInfo: TypeInfo, | ||
content: ByteReadChannel | ||
): Any? { | ||
if (typeInfo.type.qualifiedName != Document::class.qualifiedName) return null | ||
content.awaitContent() | ||
val decoder = Charsets.UTF_8.newDecoder() | ||
val string = decoder.decode(content.toInputStream().asInput()) | ||
return Jsoup.parse(string, charset.name()) | ||
} | ||
|
||
override suspend fun serializeNullable( | ||
contentType: ContentType, | ||
charset: Charset, | ||
typeInfo: TypeInfo, | ||
value: Any? | ||
): OutgoingContent? { | ||
return null | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
data-sources/api/src/nativeMain/kotlin/source/HttpMediaSource.native.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package me.him188.ani.datasources.api.source | ||
|
||
import io.ktor.serialization.ContentConverter | ||
|
||
internal actual fun getXmlConverter(): ContentConverter { | ||
TODO("Not yet implemented") | ||
} |
Oops, something went wrong.