From 9ff17b3e9a11ae1345a8b66dea5693267507418b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Braun?= Date: Tue, 7 Jan 2025 17:29:24 +0100 Subject: [PATCH 1/2] Set up Wasm proxy for Sessionize images --- .../org/jetbrains/kotlinconf/main.wasm.kt | 4 +- .../org/jetbrains/kotlinconf/main.wasm.kt | 2 + .../kotlinconf/ui/components/Speaker.kt | 8 ++-- .../org/jetbrains/kotlinconf/ui/InitCoil.kt | 38 +++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 ui-components/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/ui/InitCoil.kt diff --git a/shared/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/main.wasm.kt b/shared/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/main.wasm.kt index 122919d2..7c9918cb 100644 --- a/shared/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/main.wasm.kt +++ b/shared/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/main.wasm.kt @@ -2,10 +2,12 @@ package org.jetbrains.kotlinconf import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.window.CanvasBasedWindow +import org.jetbrains.kotlinconf.ui.initCoil @OptIn(ExperimentalComposeUiApi::class) fun main() { + initCoil() CanvasBasedWindow { App(ApplicationContext()) } -} \ No newline at end of file +} diff --git a/ui-components-gallery/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/main.wasm.kt b/ui-components-gallery/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/main.wasm.kt index 0f497ffb..1d421b44 100644 --- a/ui-components-gallery/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/main.wasm.kt +++ b/ui-components-gallery/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/main.wasm.kt @@ -3,9 +3,11 @@ package org.jetbrains.kotlinconf import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.window.CanvasBasedWindow import org.jetbrains.kotlinconf.ui.components.GalleryApp +import org.jetbrains.kotlinconf.ui.initCoil @OptIn(ExperimentalComposeUiApi::class) fun main() { + initCoil() CanvasBasedWindow { GalleryApp() } diff --git a/ui-components/src/commonMain/kotlin/org/jetbrains/kotlinconf/ui/components/Speaker.kt b/ui-components/src/commonMain/kotlin/org/jetbrains/kotlinconf/ui/components/Speaker.kt index e15da9dc..50ea8055 100644 --- a/ui-components/src/commonMain/kotlin/org/jetbrains/kotlinconf/ui/components/Speaker.kt +++ b/ui-components/src/commonMain/kotlin/org/jetbrains/kotlinconf/ui/components/Speaker.kt @@ -16,6 +16,8 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.unit.dp import coil3.compose.AsyncImage import kotlinconfapp.ui_components.generated.resources.Res +import kotlinconfapp.ui_components.generated.resources.kodee_emotion_negative +import kotlinconfapp.ui_components.generated.resources.kodee_emotion_neutral import kotlinconfapp.ui_components.generated.resources.kodee_emotion_positive import org.jetbrains.compose.resources.painterResource import org.jetbrains.compose.ui.tooling.preview.Preview @@ -43,7 +45,7 @@ fun Speaker( .background(KotlinConfTheme.colors.tileBackground), contentScale = ContentScale.Crop, placeholder = painterResource(Res.drawable.kodee_emotion_positive), - error = painterResource(Res.drawable.kodee_emotion_positive), + error = painterResource(Res.drawable.kodee_emotion_neutral), ) Column { StyledText( @@ -68,12 +70,12 @@ internal fun SpeakerPreview() { Speaker( name = "John Doe", title = "Whatever Role Name at That Company", - photoUrl = "bad bad url", + photoUrl = "https://example.com/not-an-image.jpg", ) Speaker( name = "John Doe", title = "Whatever Role Name at That Company", - photoUrl = "https://kotlinconf.com/static/sebastian-aigner-ffc95c92c3b7ade7d25a738c40015a68.png", + photoUrl = "https://sessionize.com/image/2e2f-0o0o0-XGxKBoqZvxxQxosrZHQHTT.png?download=sebastian-aigner.png", ) } } diff --git a/ui-components/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/ui/InitCoil.kt b/ui-components/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/ui/InitCoil.kt new file mode 100644 index 00000000..9b84c14a --- /dev/null +++ b/ui-components/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/ui/InitCoil.kt @@ -0,0 +1,38 @@ +package org.jetbrains.kotlinconf.ui + +import coil3.ImageLoader +import coil3.PlatformContext +import coil3.SingletonImageLoader +import coil3.intercept.Interceptor +import coil3.request.ImageResult +import coil3.util.DebugLogger + +fun initCoil() { + SingletonImageLoader.setSafe { + ImageLoader.Builder(PlatformContext.INSTANCE) + .components { + add(SessionizeImageInterceptor()) + } + .logger(DebugLogger()) + .build() + } +} + +private val sessionizeProxy = "https://sessionize-com.labs.jb.gg/" + +private class SessionizeImageInterceptor : Interceptor { + override suspend fun intercept(chain: Interceptor.Chain): ImageResult { + val originalRequest = chain.request + val data = originalRequest.data + + val newChain = if (data is String && data.startsWith("https://sessionize.com/")) { + val newUri = data.replace("https://sessionize.com/", sessionizeProxy) + val newRequest = originalRequest.newBuilder().data(newUri).build() + chain.withRequest(newRequest) + } else { + chain + } + + return newChain.proceed() + } +} From 7ad9e3e6fa4c15d8296b23d570a38881d3bc992e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Braun?= Date: Wed, 15 Jan 2025 09:55:47 +0100 Subject: [PATCH 2/2] Extract sessionize url --- .../kotlin/org/jetbrains/kotlinconf/ui/InitCoil.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ui-components/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/ui/InitCoil.kt b/ui-components/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/ui/InitCoil.kt index 9b84c14a..05f49101 100644 --- a/ui-components/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/ui/InitCoil.kt +++ b/ui-components/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/ui/InitCoil.kt @@ -18,6 +18,7 @@ fun initCoil() { } } +private val sessionizeBaseUrl = "https://sessionize.com/" private val sessionizeProxy = "https://sessionize-com.labs.jb.gg/" private class SessionizeImageInterceptor : Interceptor { @@ -25,8 +26,8 @@ private class SessionizeImageInterceptor : Interceptor { val originalRequest = chain.request val data = originalRequest.data - val newChain = if (data is String && data.startsWith("https://sessionize.com/")) { - val newUri = data.replace("https://sessionize.com/", sessionizeProxy) + val newChain = if (data is String && data.startsWith(sessionizeBaseUrl)) { + val newUri = data.replace(sessionizeBaseUrl, sessionizeProxy) val newRequest = originalRequest.newBuilder().data(newUri).build() chain.withRequest(newRequest) } else {