From 1578ba6887482a5894a24c4d6ac017f9dbf68877 Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 11 Jul 2024 18:30:55 +0800 Subject: [PATCH] feat(ui, ReaderImageViewer): add referer header with domain extraction for image proxying --- .../reader/ui/page/home/reading/ReaderImagePage.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/me/ash/reader/ui/page/home/reading/ReaderImagePage.kt b/app/src/main/java/me/ash/reader/ui/page/home/reading/ReaderImagePage.kt index 4984373..87e48a3 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/reading/ReaderImagePage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/reading/ReaderImagePage.kt @@ -41,8 +41,9 @@ import androidx.compose.ui.window.DialogWindowProvider import androidx.core.content.ContextCompat import androidx.core.view.HapticFeedbackConstantsCompat import coil.compose.rememberAsyncImagePainter - +import coil.request.ImageRequest import me.ash.reader.R +import me.ash.reader.ui.ext.extractDomain import me.ash.reader.ui.ext.showToast import me.saket.telephoto.zoomable.ZoomSpec import me.saket.telephoto.zoomable.ZoomableContentLocation @@ -72,7 +73,11 @@ fun ReaderImageViewer( val zoomableState = rememberZoomableState(zoomSpec = ZoomSpec(maxZoomFactor = 4f)) - val painter = rememberAsyncImagePainter(model = imageData.imageUrl) + val painter = rememberAsyncImagePainter( + ImageRequest.Builder(LocalContext.current).addHeader( + "Referer", imageData.imageUrl.extractDomain() ?: "" + ).data(data = imageData.imageUrl).build() + ) LaunchedEffect(painter.intrinsicSize) { zoomableState.setContentLocation( @@ -153,4 +158,4 @@ fun ReaderImageViewer( } } -} \ No newline at end of file +}