refactor(source/local): Re-organize updateCover(...)

This commit is contained in:
Ahmad Ansori Palembani 2024-07-28 11:54:44 +07:00
parent 49ecfc51b1
commit 448a582019
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -73,11 +73,13 @@ 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() ?: return null val dir = getBaseDirectory()?.findFile(manga.url)
var cover = getCoverFile(dir.findFile(manga.url)) if (dir == null) {
if (cover == null) { input.close()
cover = dir.findFile(manga.url)?.createFile(COVER_NAME)!! return null
} }
val cover = getCoverFile(dir) ?: dir.createFile(COVER_NAME)!!
// It might not exist if using the external SD card // It might not exist if using the external SD card
cover.parentFile?.parentFile?.createDirectory(cover.parentFile?.name) cover.parentFile?.parentFile?.createDirectory(cover.parentFile?.name)
input.use { input.use {