actaully make sure the chapter exists
This commit is contained in:
@@ -18,8 +18,10 @@ import org.jetbrains.exposed.sql.select
|
|||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
import org.jetbrains.exposed.sql.update
|
import org.jetbrains.exposed.sql.update
|
||||||
import suwayomi.tachidesk.manga.impl.Manga.getManga
|
import suwayomi.tachidesk.manga.impl.Manga.getManga
|
||||||
|
import suwayomi.tachidesk.manga.impl.Page.getPageName
|
||||||
import suwayomi.tachidesk.manga.impl.util.GetHttpSource.getHttpSource
|
import suwayomi.tachidesk.manga.impl.util.GetHttpSource.getHttpSource
|
||||||
import suwayomi.tachidesk.manga.impl.util.lang.awaitSingle
|
import suwayomi.tachidesk.manga.impl.util.lang.awaitSingle
|
||||||
|
import suwayomi.tachidesk.manga.impl.util.storage.CachedImageResponse
|
||||||
import suwayomi.tachidesk.manga.model.dataclass.ChapterDataClass
|
import suwayomi.tachidesk.manga.model.dataclass.ChapterDataClass
|
||||||
import suwayomi.tachidesk.manga.model.table.ChapterMetaTable
|
import suwayomi.tachidesk.manga.model.table.ChapterMetaTable
|
||||||
import suwayomi.tachidesk.manga.model.table.ChapterTable
|
import suwayomi.tachidesk.manga.model.table.ChapterTable
|
||||||
@@ -143,7 +145,15 @@ object Chapter {
|
|||||||
}.first()
|
}.first()
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (!chapterEntry[ChapterTable.isDownloaded]) {
|
val isReallyDownloaded =
|
||||||
|
chapterEntry[ChapterTable.isDownloaded] && firstPageExists(mangaId, chapterEntry[ChapterTable.id].value)
|
||||||
|
return if (!isReallyDownloaded) {
|
||||||
|
transaction {
|
||||||
|
ChapterTable.update({ (ChapterTable.chapterIndex eq chapterIndex) and (ChapterTable.manga eq mangaId) }) {
|
||||||
|
it[isDownloaded] = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val mangaEntry = transaction { MangaTable.select { MangaTable.id eq mangaId }.first() }
|
val mangaEntry = transaction { MangaTable.select { MangaTable.id eq mangaId }.first() }
|
||||||
val source = getHttpSource(mangaEntry[MangaTable.sourceReference])
|
val source = getHttpSource(mangaEntry[MangaTable.sourceReference])
|
||||||
|
|
||||||
@@ -210,6 +220,12 @@ object Chapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun firstPageExists(mangaId: Int, chapterId: Int): Boolean =
|
||||||
|
CachedImageResponse.findFileNameStartingWith(
|
||||||
|
Page.getChapterDir(mangaId, chapterId),
|
||||||
|
getPageName(0)
|
||||||
|
) != null
|
||||||
|
|
||||||
fun modifyChapter(
|
fun modifyChapter(
|
||||||
mangaId: Int,
|
mangaId: Int,
|
||||||
chapterIndex: Int,
|
chapterIndex: Int,
|
||||||
|
|||||||
@@ -51,14 +51,14 @@ object Page {
|
|||||||
|
|
||||||
val pageEntry = transaction { PageTable.select { (PageTable.chapter eq chapterId) and (PageTable.index eq index) }.first() }
|
val pageEntry = transaction { PageTable.select { (PageTable.chapter eq chapterId) and (PageTable.index eq index) }.first() }
|
||||||
|
|
||||||
val tachiPage = Page(
|
val tachiyomiPage = Page(
|
||||||
pageEntry[PageTable.index],
|
pageEntry[PageTable.index],
|
||||||
pageEntry[PageTable.url],
|
pageEntry[PageTable.url],
|
||||||
pageEntry[PageTable.imageUrl]
|
pageEntry[PageTable.imageUrl]
|
||||||
)
|
)
|
||||||
|
|
||||||
if (pageEntry[PageTable.imageUrl] == null) {
|
if (pageEntry[PageTable.imageUrl] == null) {
|
||||||
val trueImageUrl = getTrueImageUrl(tachiPage, source)
|
val trueImageUrl = getTrueImageUrl(tachiyomiPage, source)
|
||||||
transaction {
|
transaction {
|
||||||
PageTable.update({ (PageTable.chapter eq chapterId) and (PageTable.index eq index) }) {
|
PageTable.update({ (PageTable.chapter eq chapterId) and (PageTable.index eq index) }) {
|
||||||
it[imageUrl] = trueImageUrl
|
it[imageUrl] = trueImageUrl
|
||||||
@@ -68,15 +68,18 @@ object Page {
|
|||||||
|
|
||||||
val saveDir = getChapterDir(mangaId, chapterId)
|
val saveDir = getChapterDir(mangaId, chapterId)
|
||||||
File(saveDir).mkdirs()
|
File(saveDir).mkdirs()
|
||||||
val fileName = String.format("%03d", index) // e.g. 001.jpeg
|
val fileName = getPageName(index) // e.g. 001
|
||||||
|
|
||||||
return getCachedImageResponse(saveDir, fileName) {
|
return getCachedImageResponse(saveDir, fileName) {
|
||||||
source.fetchImage(tachiPage).awaitSingle()
|
source.fetchImage(tachiyomiPage).awaitSingle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getPageName(index: Int): String = String.format("%03d", index)
|
||||||
|
|
||||||
private val applicationDirs by DI.global.instance<ApplicationDirs>()
|
private val applicationDirs by DI.global.instance<ApplicationDirs>()
|
||||||
private fun getChapterDir(mangaId: Int, chapterId: Int): String {
|
|
||||||
|
fun getChapterDir(mangaId: Int, chapterId: Int): String {
|
||||||
val mangaEntry = transaction { MangaTable.select { MangaTable.id eq mangaId }.first() }
|
val mangaEntry = transaction { MangaTable.select { MangaTable.id eq mangaId }.first() }
|
||||||
val source = getHttpSource(mangaEntry[MangaTable.sourceReference])
|
val source = getHttpSource(mangaEntry[MangaTable.sourceReference])
|
||||||
val chapterEntry = transaction { ChapterTable.select { ChapterTable.id eq chapterId }.first() }
|
val chapterEntry = transaction { ChapterTable.select { ChapterTable.id eq chapterId }.first() }
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ object CachedImageResponse {
|
|||||||
return FileInputStream(path).buffered()
|
return FileInputStream(path).buffered()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findFileNameStartingWith(directoryPath: String, fileName: String): String? {
|
fun findFileNameStartingWith(directoryPath: String, fileName: String): String? {
|
||||||
val target = "$fileName."
|
val target = "$fileName."
|
||||||
File(directoryPath).listFiles().orEmpty().forEach { file ->
|
File(directoryPath).listFiles().orEmpty().forEach { file ->
|
||||||
if (file.name.startsWith(target))
|
if (file.name.startsWith(target))
|
||||||
|
|||||||
Reference in New Issue
Block a user