From d83ddea3238e40d6da9a95aa81d4c1811f16b3c0 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Sat, 18 Sep 2021 14:49:22 +0430 Subject: [PATCH] better URLs --- .../kotlin/eu/kanade/tachiyomi/source/LocalSource.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/src/main/kotlin/eu/kanade/tachiyomi/source/LocalSource.kt b/server/src/main/kotlin/eu/kanade/tachiyomi/source/LocalSource.kt index 1fad2a0e..8f4e8738 100644 --- a/server/src/main/kotlin/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/server/src/main/kotlin/eu/kanade/tachiyomi/source/LocalSource.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.source // import com.github.junrar.Archive // import java.util.zip.ZipFile +import eu.kanade.tachiyomi.source.FileSystemInterceptor.fakeUrlFrom import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage @@ -61,7 +62,7 @@ class LocalSource(override val baseUrl: String = "") : HttpSource() { private val LATEST_THRESHOLD = TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS) -// fun updateCover(context: Context, manga: SManga, input: InputStream): File? { + // fun updateCover(context: Context, manga: SManga, input: InputStream): File? { // val dir = getBaseDirectories(context).firstOrNull() // if (dir == null) { // input.close() @@ -171,7 +172,7 @@ class LocalSource(override val baseUrl: String = "") : HttpSource() { // Try to find the cover val cover = File("${applicationDirs.localMangaRoot}/$url/cover.jpg") if (cover.exists()) { - thumbnail_url = "http://${cover.absolutePath}" + thumbnail_url = fakeUrlFrom(cover.absolutePath) } // val chapters = fetchChapterList(this).toBlocking().first() @@ -293,14 +294,14 @@ class LocalSource(override val baseUrl: String = "") : HttpSource() { } override fun fetchPageList(chapter: SChapter): Observable> { - val chapterFile = File(applicationDirs.localMangaRoot + File.separator + chapter.url) + val chapterFile = File(applicationDirs.localMangaRoot + "/" + chapter.url) return Observable.just( if (chapterFile.isDirectory) { chapterFile.listFiles().sortedBy { it.name }.mapIndexed { index, page -> Page( index, - imageUrl = "http://" + applicationDirs.localMangaRoot + File.separator + chapter.url + File.separator + page.name + imageUrl = fakeUrlFrom(applicationDirs.localMangaRoot + "/" + chapter.url + "/" + page.name) ) } } else { @@ -419,6 +420,8 @@ class LocalSource(override val baseUrl: String = "") : HttpSource() { } private object FileSystemInterceptor : Interceptor { + fun fakeUrlFrom(path: String) = "http://$path" + private fun restoreFileUrl(markedFakeHttpUrl: String): String { return markedFakeHttpUrl.replaceFirst("http:", "file:/") }