Skip to content

Commit

Permalink
Merge pull request #222 from JetBrains/wasm-proxy
Browse files Browse the repository at this point in the history
Set up Wasm proxy for Sessionize images
  • Loading branch information
zsmb13 authored Jan 15, 2025
2 parents 9cbe8e4 + 7ad9e3e commit e8ec1c9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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",
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 sessionizeBaseUrl = "https://sessionize.com/"
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(sessionizeBaseUrl)) {
val newUri = data.replace(sessionizeBaseUrl, sessionizeProxy)
val newRequest = originalRequest.newBuilder().data(newUri).build()
chain.withRequest(newRequest)
} else {
chain
}

return newChain.proceed()
}
}

0 comments on commit e8ec1c9

Please sign in to comment.