-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from JetBrains/wasm-proxy
Set up Wasm proxy for Sessionize images
- Loading branch information
Showing
4 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
ui-components/src/wasmJsMain/kotlin/org/jetbrains/kotlinconf/ui/InitCoil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |