feat(ui): add referer header with domain extraction for image proxying (#795)

This commit is contained in:
Ash 2024-07-11 18:06:53 +08:00 committed by GitHub
parent fe62743356
commit e795daedc8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 5 deletions

View File

@ -11,15 +11,13 @@ import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import coil.compose.rememberAsyncImagePainter
import coil.compose.rememberImagePainter
import coil.request.ImageRequest
import coil.size.Precision
import coil.size.Scale
import coil.size.Size
import me.ash.reader.R
import me.ash.reader.ui.ext.extractDomain
val SIZE_1000 = Size(1000, 1000)
@ -37,7 +35,9 @@ fun RYAsyncImage(
) {
Image(
painter = rememberAsyncImagePainter(
ImageRequest.Builder(LocalContext.current).data(data = data).apply {
ImageRequest.Builder(LocalContext.current).addHeader(
"Referer", (data as String).extractDomain() ?: ""
).data(data = data).apply {
if (placeholder != null) placeholder(placeholder)
if (error != null) error(error)
crossfade(true)
@ -141,4 +141,4 @@ private val DefaultOnDraw: DrawScope.(ForwardingDrawInfo) -> Unit = { info ->
info.colorFilter
)
}
}
}