Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up Wasm proxy for Sessionize images #222

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}
Loading