Support Referer header for image requests

This commit is contained in:
Koitharu
2021-01-07 14:48:35 +02:00
parent 22e7bab879
commit 1a0986212b
22 changed files with 55 additions and 19 deletions

View File

@@ -7,6 +7,7 @@ import org.koitharu.kotatsu.utils.ext.longHashCode
import org.koitharu.kotatsu.utils.ext.sub
import org.koitharu.kotatsu.utils.ext.takeIfReadable
import java.io.File
import java.io.InputStream
import java.io.OutputStream
class PagesCache(context: Context) {
@@ -19,6 +20,7 @@ class PagesCache(context: Context) {
return lruCache.get(url)?.takeIfReadable()
}
@Deprecated("Useless lambda")
fun put(url: String, writer: (OutputStream) -> Unit): File {
val file = cacheDir.sub(url.longHashCode().toString())
file.outputStream().use(writer)
@@ -26,4 +28,14 @@ class PagesCache(context: Context) {
file.delete()
return res
}
fun put(url: String, inputStream: InputStream): File {
val file = cacheDir.sub(url.longHashCode().toString())
file.outputStream().use { out ->
inputStream.copyTo(out)
}
val res = lruCache.put(url, file)
file.delete()
return res
}
}

View File

@@ -71,6 +71,7 @@ class LocalMangaRepository(private val context: Context) : MangaRepository {
MangaPage(
id = entryUri.longHashCode(),
url = entryUri,
referer = chapter.url,
source = MangaSource.LOCAL
)
}