mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
fix(LocalSource): Local entry cover won't load
This commit is contained in:
parent
2393ddf9ce
commit
a98ba32b43
2 changed files with 21 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
package eu.kanade.tachiyomi.data.coil
|
||||
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.core.net.toUri
|
||||
import coil3.Extras
|
||||
import coil3.ImageLoader
|
||||
import coil3.decode.DataSource
|
||||
|
@ -11,6 +12,7 @@ import coil3.fetch.Fetcher
|
|||
import coil3.fetch.SourceFetchResult
|
||||
import coil3.getOrDefault
|
||||
import coil3.request.Options
|
||||
import com.hippo.unifile.UniFile
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.network.await
|
||||
|
@ -31,6 +33,7 @@ import okio.Path.Companion.toOkioPath
|
|||
import okio.Source
|
||||
import okio.buffer
|
||||
import okio.sink
|
||||
import okio.source
|
||||
import timber.log.Timber
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.io.File
|
||||
|
@ -61,6 +64,7 @@ class MangaCoverFetcher(
|
|||
setRatioAndColorsInScope(manga, File(url.substringAfter("file://")))
|
||||
fileLoader(File(url.substringAfter("file://")))
|
||||
}
|
||||
Type.URI -> fileUriLoader(url)
|
||||
null -> error("Invalid image")
|
||||
}
|
||||
}
|
||||
|
@ -304,11 +308,24 @@ class MangaCoverFetcher(
|
|||
)
|
||||
}
|
||||
|
||||
private fun fileUriLoader(uri: String): FetchResult {
|
||||
val source = UniFile.fromUri(options.context, uri.toUri())!!
|
||||
.openInputStream()
|
||||
.source()
|
||||
.buffer()
|
||||
return SourceFetchResult(
|
||||
source = ImageSource(source = source, fileSystem = FileSystem.SYSTEM),
|
||||
mimeType = "image/*",
|
||||
dataSource = DataSource.DISK,
|
||||
)
|
||||
}
|
||||
|
||||
private fun getResourceType(cover: String?): Type? {
|
||||
return when {
|
||||
cover.isNullOrEmpty() -> null
|
||||
cover.startsWith("http") || cover.startsWith("Custom-", true) -> Type.URL
|
||||
cover.startsWith("/") || cover.startsWith("file://") -> Type.File
|
||||
cover.startsWith("content") -> Type.URI
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
@ -328,7 +345,7 @@ class MangaCoverFetcher(
|
|||
}
|
||||
|
||||
private enum class Type {
|
||||
File, URL;
|
||||
File, URL, URI;
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -54,7 +54,7 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
|
|||
}
|
||||
}
|
||||
|
||||
fun updateCover(manga: SManga, input: InputStream): UniFile? {
|
||||
fun updateCover(manga: SManga, input: InputStream): UniFile {
|
||||
val dir = getBaseDirectory()
|
||||
var cover = getCoverFile(dir.findFile(manga.url))
|
||||
if (cover == null) {
|
||||
|
@ -67,7 +67,7 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
|
|||
input.copyTo(it)
|
||||
}
|
||||
}
|
||||
manga.thumbnail_url = cover.filePath
|
||||
manga.thumbnail_url = cover.uri.toString()
|
||||
return cover
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
|
|||
// Try to find the cover
|
||||
val cover = getCoverFile(mangaDir)
|
||||
if (cover != null && cover.exists()) {
|
||||
thumbnail_url = cover.filePath
|
||||
thumbnail_url = cover.uri.toString()
|
||||
}
|
||||
|
||||
val manga = this
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue