Convert :source-api and :source-local to android library module (#3636)

- There's really no plan to support other platforms on this code base
- The "KMP" modules only had android target which is rather pointless
- `i18n` involves more work but given it has no actual code keeping it as is
This commit is contained in:
AntsyLich
2026-07-23 22:47:24 +06:00
committed by GitHub
parent 47d7c0f2ea
commit 9c3cc1ca5f
38 changed files with 54 additions and 128 deletions
@@ -0,0 +1,50 @@
package tachiyomi.source.local.image
import android.content.Context
import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.util.storage.DiskUtil
import tachiyomi.core.common.storage.nameWithoutExtension
import tachiyomi.core.common.util.system.ImageUtil
import tachiyomi.source.local.io.LocalSourceFileSystem
import java.io.InputStream
private const val DEFAULT_COVER_NAME = "cover.jpg"
class LocalCoverManager(
private val context: Context,
private val fileSystem: LocalSourceFileSystem,
) {
fun find(mangaUrl: String): UniFile? {
return fileSystem.getFilesInMangaDirectory(mangaUrl)
// Get all file whose names start with "cover"
.filter { it.isFile && it.nameWithoutExtension.equals("cover", ignoreCase = true) }
// Get the first actual image
.firstOrNull { ImageUtil.isImage(it.name) { it.openInputStream() } }
}
fun update(
manga: SManga,
inputStream: InputStream,
): UniFile? {
val directory = fileSystem.getMangaDirectory(manga.url)
if (directory == null) {
inputStream.close()
return null
}
val targetFile = find(manga.url) ?: directory.createFile(DEFAULT_COVER_NAME)!!
inputStream.use { input ->
targetFile.openOutputStream().use { output ->
input.copyTo(output)
}
}
DiskUtil.createNoMediaFile(directory, context)
manga.thumbnail_url = targetFile.uri.toString()
return targetFile
}
}