feat(ui, ReaderImageViewer): add referer header with domain extraction for image proxying

This commit is contained in:
Ash 2024-07-11 18:30:55 +08:00
parent e795daedc8
commit 1578ba6887
No known key found for this signature in database
1 changed files with 8 additions and 3 deletions

View File

@ -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(
}
}
}
}