Manga dir

This commit is contained in:
Aria Moradi 2021-02-03 23:35:34 +03:30
parent 9e308025c3
commit 172f83f5b3
2 changed files with 19 additions and 1 deletions

View File

@ -10,4 +10,5 @@ object Config {
val dataRoot = AppDirsFactory.getInstance().getUserDataDir("Tachidesk", null, null)
val extensionsRoot = "$dataRoot/extensions"
val thumbnailsRoot = "$dataRoot/thumbnails"
val mangaRoot = "$dataRoot/manga"
}

View File

@ -10,9 +10,12 @@ import ir.armor.tachidesk.Config
import ir.armor.tachidesk.database.dataclass.MangaDataClass
import ir.armor.tachidesk.database.table.MangaStatus
import ir.armor.tachidesk.database.table.MangaTable
import ir.armor.tachidesk.database.table.SourceTable
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update
import java.io.File
import java.io.InputStream
import java.util.concurrent.ArrayBlockingQueue
@ -128,8 +131,8 @@ fun getManga(mangaId: Int, proxyThumbnail: Boolean = true): MangaDataClass {
fun getThumbnail(mangaId: Int): Pair<InputStream, String> {
return transaction {
var filePath = Config.thumbnailsRoot + "/$mangaId"
var mangaEntry = MangaTable.select { MangaTable.id eq mangaId }.firstOrNull()!!
var filePath = Config.thumbnailsRoot + "/$mangaId"
val potentialCache = findFileNameStartingWith(Config.thumbnailsRoot, mangaId.toString())
if (potentialCache != null) {
@ -169,3 +172,17 @@ fun getThumbnail(mangaId: Int): Pair<InputStream, String> {
}
}
}
fun getMangaDir(mangaId: Int): String {
val mangaEntry = MangaTable.select { MangaTable.id eq mangaId }.firstOrNull()!!
val sourceId = mangaEntry[MangaTable.sourceReference].value
val sourceEntry = SourceTable.select { SourceTable.id eq sourceId }.firstOrNull()!!
val mangaTitle = mangaEntry[MangaTable.title]
val sourceName = sourceEntry[SourceTable.name]
val mangaDir = "${Config.mangaRoot}/$sourceName/$mangaTitle"
// make sure dirs exist
File(mangaDir).mkdirs()
return mangaDir
}