diff --git a/build.gradle.kts b/build.gradle.kts index 09cb2db3a..f6f527329 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ plugins { } object Versions { - const val Ktor = "1.5.4" + const val Ktor = "1.6.0" const val JsonKt = "6.1.1" const val KotlinxSerializationJson = "1.2.1" const val uuid = "0.3.0" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e5338d370..69a971507 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/commonMain/kotlin/blue/starry/penicillin/core/request/action/Action.kt b/src/commonMain/kotlin/blue/starry/penicillin/core/request/action/Action.kt index 9cebed4e3..c76232bd6 100644 --- a/src/commonMain/kotlin/blue/starry/penicillin/core/request/action/Action.kt +++ b/src/commonMain/kotlin/blue/starry/penicillin/core/request/action/Action.kt @@ -93,7 +93,7 @@ internal fun checkError(request: HttpRequest, response: HttpResponse, content: S is JsonObject -> { val code by error.byNullableInt val message by error.byNullableString - + throwApiError(code, message.orEmpty(), content!!, request, response) } is JsonPrimitive -> { @@ -109,13 +109,9 @@ internal fun checkError(request: HttpRequest, response: HttpResponse, content: S } internal suspend inline fun HttpResponse.readTextOrNull(): String? { - return runCatching { - readText().unescapeHTML() + return runCatching { + readText() }.onFailure { - apiActionLogger.debug(it) { "Could not readText." } + apiActionLogger.debug(it) { "Failed to read text." } }.getOrNull() } - -internal fun String.unescapeHTML(): String { - return replace("&", "&").replace("<", "<").replace(">", ">") -} diff --git a/src/commonMain/kotlin/blue/starry/penicillin/core/request/action/StreamApiAction.kt b/src/commonMain/kotlin/blue/starry/penicillin/core/request/action/StreamApiAction.kt index 255e3d116..b8f2c40ed 100644 --- a/src/commonMain/kotlin/blue/starry/penicillin/core/request/action/StreamApiAction.kt +++ b/src/commonMain/kotlin/blue/starry/penicillin/core/request/action/StreamApiAction.kt @@ -79,26 +79,25 @@ public class StreamApiAction>( while (!channel.isClosedForRead) { val line = channel.readUTF8Line() ?: continue - val content = line.unescapeHTML() when { - content.startsWith('{') -> { - handler.handle(content.toJsonObject()) + line.startsWith('{') -> { + handler.handle(line.toJsonObject()) } - content.isBlank() -> { + line.isBlank() -> { listener.onHeartbeat() } else -> { - val length = content.toIntOrNull() + val length = line.toIntOrNull() if (length != null) { listener.onLength(length) } else { - listener.onUnknownData(content) + listener.onUnknownData(line) } } } - listener.onRawData(content) + listener.onRawData(line) } listener.onDisconnect(null) diff --git a/src/commonMain/kotlin/blue/starry/penicillin/extensions/models/StatusText.kt b/src/commonMain/kotlin/blue/starry/penicillin/extensions/models/StatusText.kt index 8b19de175..3fe265206 100644 --- a/src/commonMain/kotlin/blue/starry/penicillin/extensions/models/StatusText.kt +++ b/src/commonMain/kotlin/blue/starry/penicillin/extensions/models/StatusText.kt @@ -29,7 +29,7 @@ package blue.starry.penicillin.extensions.models import blue.starry.penicillin.models.Status /** - * Returns full-body status text. + * Returns full-body, unescaped status text. * Supports both tweet modes (Extend and Compat). */ public val Status.text: String @@ -37,11 +37,11 @@ public val Status.text: String if (retweetedStatus?.extendedTweet != null) { "RT @${retweetedStatus!!.user.screenName}: ${retweetedStatus!!.text}" } else { - fullTextRaw ?: textRaw ?: throw IllegalStateException("Unsupported status format: $json") + fullTextRaw ?: textRaw ?: error("Unsupported status format: $json") } } else { - extendedTweet?.fullText ?: fullTextRaw ?: textRaw ?: throw IllegalStateException("Unsupported status format: $json") - } + extendedTweet?.fullText ?: fullTextRaw ?: textRaw ?: error("Unsupported status format: $json") + }.unescapeHTML() /** * Returns full-body status text which shortened urls in are each expanded. @@ -80,3 +80,9 @@ public val Status.expandedTextWithIndices: String } } } + +private fun String.unescapeHTML(): String { + return replace("&", "&") + .replace("<", "<") + .replace(">", ">") +} diff --git a/src/jsMain/kotlin/blue/starry/penicillin/extensions/runBlocking.kt b/src/jsMain/kotlin/blue/starry/penicillin/extensions/runBlocking.kt index c34cb1d62..e50ff1d46 100644 --- a/src/jsMain/kotlin/blue/starry/penicillin/extensions/runBlocking.kt +++ b/src/jsMain/kotlin/blue/starry/penicillin/extensions/runBlocking.kt @@ -25,6 +25,7 @@ package blue.starry.penicillin.extensions import blue.starry.penicillin.core.experimental.PenicillinExperimentalApi +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.promise import mu.KLogger @@ -34,6 +35,7 @@ import kotlin.coroutines.CoroutineContext @PublishedApi internal val promiseLogger: KLogger = KotlinLogging.logger("Penicillin.PromiseLogger") +@OptIn(DelicateCoroutinesApi::class) @PenicillinExperimentalApi internal actual fun runBlockingAlt( context: CoroutineContext, diff --git a/src/jvmTest/kotlin/tests/Utilities.kt b/src/jvmTest/kotlin/tests/Utilities.kt index e4d3306d5..958f472bb 100644 --- a/src/jvmTest/kotlin/tests/Utilities.kt +++ b/src/jvmTest/kotlin/tests/Utilities.kt @@ -26,6 +26,7 @@ package tests +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import mu.KotlinLogging @@ -49,6 +50,7 @@ internal inline fun measurePerformance(label: String, block: () -> T): T { return result as T } +@OptIn(DelicateCoroutinesApi::class) internal inline fun measurePerformanceAsync(label: String, crossinline block: () -> Unit) { if (!logger.isTraceEnabled) { block()