From f645bbd46e461d6015a2b424794e14c074b213c1 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 28 Jul 2024 17:25:21 +0100 Subject: [PATCH] [commonize] #496 Update ktor to 3.0.0 and update submodules Ksoup depends on 3.0.0 so we have to update. Otherwise there will be missing classes. --- app/shared/build.gradle.kts | 2 +- app/shared/proguard-rules.pro | 72 ------------------- app/shared/reorderable | 2 +- .../kotlin/ui/foundation/AsyncImage.kt | 2 +- .../him188/ani/client/infrastructure/Bytes.kt | 1 + .../kotlin/source/HttpMediaSource.jvm.kt | 7 +- .../api/test-codegen/src/main/AddMoreData.kt | 7 +- gradle/libs.versions.toml | 3 +- .../src/nativeMain/kotlin/KtorIO.native.kt | 1 + .../src/commonMain/kotlin/ktor/KtorCompact.kt | 6 ++ utils/xml/ksoup | 2 +- 11 files changed, 20 insertions(+), 85 deletions(-) create mode 100644 utils/platform/src/commonMain/kotlin/ktor/KtorCompact.kt diff --git a/app/shared/build.gradle.kts b/app/shared/build.gradle.kts index 608db650f1..5dd41e8980 100644 --- a/app/shared/build.gradle.kts +++ b/app/shared/build.gradle.kts @@ -98,7 +98,7 @@ kotlin { api(libs.coil.core) api(libs.coil.svg) api(libs.coil.compose.core) - api(libs.coil.network.ktor2) + api(libs.coil.network.ktor3) api(libs.datastore.core) // Data Persistence api(libs.datastore.preferences.core) // Preferences api(libs.precompose) // Navigator diff --git a/app/shared/proguard-rules.pro b/app/shared/proguard-rules.pro index f30819fa51..1c9bd3ec29 100644 --- a/app/shared/proguard-rules.pro +++ b/app/shared/proguard-rules.pro @@ -70,75 +70,3 @@ # anitorrent -keep class me.him188.ani.app.torrent.anitorrent.binding.** { *; } - - -# Keep the specified classes and all their members --keep class io.ktor.client.network.sockets.TimeoutExceptionsCommonKt { *; } --keep class io.ktor.client.plugins.HttpRedirect$Config { *; } --keep class io.ktor.client.plugins.HttpRedirect$Plugin { *; } --keep class io.ktor.client.plugins.HttpRedirect { *; } --keep class io.ktor.client.plugins.HttpRequestRetry$Configuration { *; } --keep class io.ktor.client.plugins.HttpRequestRetry$DelayContext { *; } --keep class io.ktor.client.plugins.HttpRequestRetry$Plugin { *; } --keep class io.ktor.client.plugins.HttpRequestRetry { *; } --keep class io.ktor.client.plugins.HttpTimeout$HttpTimeoutCapabilityConfiguration { *; } --keep class io.ktor.client.plugins.HttpTimeout$Plugin { *; } --keep class io.ktor.client.plugins.HttpTimeout { *; } --keep class io.ktor.client.plugins.UserAgent$Config { *; } --keep class io.ktor.client.plugins.UserAgent$Plugin { *; } --keep class io.ktor.client.plugins.UserAgent { *; } --keep class io.ktor.util.InternalAPI { *; } --keep class io.ktor.util.KtorDsl { *; } --keep class io.ktor.utils.io.ByteReadChannelJVMKt { *; } --keep class io.ktor.utils.io.CoroutinesKt { *; } --keep class io.ktor.utils.io.ReadSessionKt { *; } --keep class io.ktor.utils.io.core.Buffer$Companion { *; } --keep class io.ktor.utils.io.core.Buffer { *; } --keep class io.ktor.utils.io.core.ByteBuffersKt { *; } --keep class io.ktor.utils.io.core.BytePacketBuilder { *; } --keep class io.ktor.utils.io.core.ByteReadPacket$Companion { *; } --keep class io.ktor.utils.io.core.ByteReadPacket { *; } --keep class io.ktor.utils.io.core.CloseableJVMKt { *; } --keep class io.ktor.utils.io.core.Input { *; } --keep class io.ktor.utils.io.core.InputArraysKt { *; } --keep class io.ktor.utils.io.core.InputPrimitivesKt { *; } --keep class io.ktor.utils.io.core.Output { *; } --keep class io.ktor.utils.io.core.OutputPrimitivesKt { *; } --keep class io.ktor.utils.io.core.PreviewKt { *; } --keep class io.ktor.utils.io.jvm.nio.WritingKt { *; } --keep class io.ktor.utils.io.streams.InputKt { *; } - --dontwarn io.ktor.client.network.sockets.TimeoutExceptionsCommonKt --dontwarn io.ktor.client.plugins.HttpRedirect$Config --dontwarn io.ktor.client.plugins.HttpRedirect$Plugin --dontwarn io.ktor.client.plugins.HttpRedirect --dontwarn io.ktor.client.plugins.HttpRequestRetry$Configuration --dontwarn io.ktor.client.plugins.HttpRequestRetry$DelayContext --dontwarn io.ktor.client.plugins.HttpRequestRetry$Plugin --dontwarn io.ktor.client.plugins.HttpRequestRetry --dontwarn io.ktor.client.plugins.HttpTimeout$HttpTimeoutCapabilityConfiguration --dontwarn io.ktor.client.plugins.HttpTimeout$Plugin --dontwarn io.ktor.client.plugins.HttpTimeout --dontwarn io.ktor.client.plugins.UserAgent$Config --dontwarn io.ktor.client.plugins.UserAgent$Plugin --dontwarn io.ktor.client.plugins.UserAgent --dontwarn io.ktor.util.InternalAPI --dontwarn io.ktor.util.KtorDsl --dontwarn io.ktor.utils.io.ByteReadChannelJVMKt --dontwarn io.ktor.utils.io.CoroutinesKt --dontwarn io.ktor.utils.io.ReadSessionKt --dontwarn io.ktor.utils.io.core.Buffer$Companion --dontwarn io.ktor.utils.io.core.Buffer --dontwarn io.ktor.utils.io.core.ByteBuffersKt --dontwarn io.ktor.utils.io.core.BytePacketBuilder --dontwarn io.ktor.utils.io.core.ByteReadPacket$Companion --dontwarn io.ktor.utils.io.core.ByteReadPacket --dontwarn io.ktor.utils.io.core.CloseableJVMKt --dontwarn io.ktor.utils.io.core.Input --dontwarn io.ktor.utils.io.core.InputArraysKt --dontwarn io.ktor.utils.io.core.InputPrimitivesKt --dontwarn io.ktor.utils.io.core.Output --dontwarn io.ktor.utils.io.core.OutputPrimitivesKt --dontwarn io.ktor.utils.io.core.PreviewKt --dontwarn io.ktor.utils.io.jvm.nio.WritingKt --dontwarn io.ktor.utils.io.streams.InputKt \ No newline at end of file diff --git a/app/shared/reorderable b/app/shared/reorderable index 5ad18c24d5..5dbdc7a366 160000 --- a/app/shared/reorderable +++ b/app/shared/reorderable @@ -1 +1 @@ -Subproject commit 5ad18c24d5a28ab53ff010efbcc6c2030190f110 +Subproject commit 5dbdc7a366d51d5e084b845b1afa98cd0aee2533 diff --git a/app/shared/src/commonMain/kotlin/ui/foundation/AsyncImage.kt b/app/shared/src/commonMain/kotlin/ui/foundation/AsyncImage.kt index c913eab1ac..7afc257ca1 100644 --- a/app/shared/src/commonMain/kotlin/ui/foundation/AsyncImage.kt +++ b/app/shared/src/commonMain/kotlin/ui/foundation/AsyncImage.kt @@ -15,7 +15,7 @@ import coil3.compose.AsyncImagePainter import coil3.compose.DefaultModelEqualityDelegate import coil3.compose.EqualityDelegate import coil3.memory.MemoryCache -import coil3.network.ktor2.KtorNetworkFetcherFactory +import coil3.network.ktor3.KtorNetworkFetcherFactory import coil3.request.CachePolicy import coil3.request.crossfade import coil3.svg.SvgDecoder diff --git a/client/src/commonMain/gen/me/him188/ani/client/infrastructure/Bytes.kt b/client/src/commonMain/gen/me/him188/ani/client/infrastructure/Bytes.kt index af0ee23afe..70ad469f2a 100644 --- a/client/src/commonMain/gen/me/him188/ani/client/infrastructure/Bytes.kt +++ b/client/src/commonMain/gen/me/him188/ani/client/infrastructure/Bytes.kt @@ -5,6 +5,7 @@ import io.ktor.utils.io.core.Input import io.ktor.utils.io.core.buildPacket import io.ktor.utils.io.core.readAvailable import io.ktor.utils.io.core.readBytes +import io.ktor.utils.io.core.remaining import io.ktor.utils.io.core.writeFully import io.ktor.utils.io.core.writeText import kotlin.experimental.and diff --git a/data-sources/api/src/jvmMain/kotlin/source/HttpMediaSource.jvm.kt b/data-sources/api/src/jvmMain/kotlin/source/HttpMediaSource.jvm.kt index 74646f2a8a..f916d5f1c9 100644 --- a/data-sources/api/src/jvmMain/kotlin/source/HttpMediaSource.jvm.kt +++ b/data-sources/api/src/jvmMain/kotlin/source/HttpMediaSource.jvm.kt @@ -12,7 +12,6 @@ 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() @@ -20,7 +19,7 @@ internal actual fun getXmlConverter(): ContentConverter = XmlConverter private object XmlConverter : ContentConverter { override suspend fun deserialize( - charset: Charset, + charset: java.nio.charset.Charset, typeInfo: TypeInfo, content: ByteReadChannel ): Any? { @@ -31,9 +30,9 @@ private object XmlConverter : ContentConverter { return Jsoup.parse(string, charset.name()) } - override suspend fun serializeNullable( + override suspend fun serialize( contentType: ContentType, - charset: Charset, + charset: io.ktor.utils.io.charsets.Charset, typeInfo: TypeInfo, value: Any? ): OutgoingContent? { diff --git a/data-sources/api/test-codegen/src/main/AddMoreData.kt b/data-sources/api/test-codegen/src/main/AddMoreData.kt index de4094c2d3..7f0c94eb59 100644 --- a/data-sources/api/test-codegen/src/main/AddMoreData.kt +++ b/data-sources/api/test-codegen/src/main/AddMoreData.kt @@ -26,7 +26,6 @@ import me.him188.ani.datasources.dmhy.impl.protocol.Network import org.jsoup.Jsoup import org.jsoup.nodes.Document import java.io.File -import java.nio.charset.Charset /** @@ -77,7 +76,7 @@ class TopicFetcher( ContentType.Text.Html, object : ContentConverter { override suspend fun deserialize( - charset: Charset, + charset: io.ktor.utils.io.charsets.Charset, typeInfo: TypeInfo, content: ByteReadChannel ): Any? { @@ -88,9 +87,9 @@ class TopicFetcher( return Jsoup.parse(string, charset.name()) } - override suspend fun serializeNullable( + override suspend fun serialize( contentType: ContentType, - charset: Charset, + charset: io.ktor.utils.io.charsets.Charset, typeInfo: TypeInfo, value: Any? ): OutgoingContent? { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1fa832e39c..e82ca5a031 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,7 +19,7 @@ okio = "3.9.0" korlibs = "6.0.0" playwright = "1.44.0" reorderable = "0.9.6" -ktor = "2.3.12" +ktor = "3.0.0-beta-2" # Ksoup 用 3.0 所以我们不得不用 3.0 koin = "4.0.0-RC1" # https://github.com/InsertKoinIO/koin/releases slf4j = "2.0.12" jsoup = "1.15.4" @@ -135,6 +135,7 @@ coil-svg = { module = "io.coil-kt.coil3:coil-svg", version.ref = "coil" } #coil-gif = { module = "io.coil-kt.coil3:coil-gif", version.ref = "coil" } coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coil" } coil-network-ktor2 = { module = "io.coil-kt.coil3:coil-network-ktor2", version.ref = "coil" } +coil-network-ktor3 = { module = "io.coil-kt.coil3:coil-network-ktor3", version.ref = "coil" } # Jsoup - HTML parsing (for dmhy) jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" } diff --git a/utils/ktor-client/src/nativeMain/kotlin/KtorIO.native.kt b/utils/ktor-client/src/nativeMain/kotlin/KtorIO.native.kt index 36fc0f0cd9..4311807c12 100644 --- a/utils/ktor-client/src/nativeMain/kotlin/KtorIO.native.kt +++ b/utils/ktor-client/src/nativeMain/kotlin/KtorIO.native.kt @@ -2,6 +2,7 @@ package me.him188.ani.utils.ktor import io.ktor.utils.io.ByteReadChannel import io.ktor.utils.io.cancel +import io.ktor.utils.io.readAvailable import kotlinx.coroutines.runBlocking import kotlinx.io.Buffer import kotlinx.io.RawSource diff --git a/utils/platform/src/commonMain/kotlin/ktor/KtorCompact.kt b/utils/platform/src/commonMain/kotlin/ktor/KtorCompact.kt new file mode 100644 index 0000000000..1b693f3672 --- /dev/null +++ b/utils/platform/src/commonMain/kotlin/ktor/KtorCompact.kt @@ -0,0 +1,6 @@ +@file:Suppress("PackageDirectoryMismatch") + +package io.ktor.util + +@RequiresOptIn(level = RequiresOptIn.Level.WARNING) +annotation class InternalAPI diff --git a/utils/xml/ksoup b/utils/xml/ksoup index 8b0c159200..be4672c6cf 160000 --- a/utils/xml/ksoup +++ b/utils/xml/ksoup @@ -1 +1 @@ -Subproject commit 8b0c1592001c603cbfe519490c2812b20b221741 +Subproject commit be4672c6cf6e19ac268e487e7a26fb144b9716cd