diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt index 0456b46..c0b7c2b 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt @@ -30,10 +30,10 @@ object Chapter { val source = getHttpSource(mangaDetails.sourceId.toLong()) val chapterList = source.fetchChapterList( - SManga.create().apply { - title = mangaDetails.title - url = mangaDetails.url - } + SManga.create().apply { + title = mangaDetails.title + url = mangaDetails.url + } ).awaitSingle() val chapterCount = chapterList.count() @@ -69,17 +69,30 @@ object Chapter { val dbChapterCount = transaction { ChapterTable.selectAll().count() } if (dbChapterCount > chapterCount) { // we got some clean up due // TODO: delete orphan chapters + val dbChapterList = transaction { ChapterTable.selectAll().orderBy() } + } + val dbChapters = transaction { ChapterTable.selectAll() } + .associateBy({ it[ChapterTable.url] }, { it }) + chapterList.mapIndexed { index, it -> + + val dbChapter = dbChapters.getValue(it.url) + ChapterDataClass( - it.url, - it.name, - it.date_upload, - it.chapter_number, - it.scanlator, - mangaId, - chapterCount - index, + it.url, + it.name, + it.date_upload, + it.chapter_number, + it.scanlator, + mangaId, + + dbChapter[ChapterTable.isRead], + dbChapter[ChapterTable.isBookmarked], + dbChapter[ChapterTable.lastPageRead], + + chapterCount - index, ) } } @@ -96,10 +109,10 @@ object Chapter { val source = getHttpSource(mangaEntry[MangaTable.sourceReference]) val pageList = source.fetchPageList( - SChapter.create().apply { - url = chapterEntry[ChapterTable.url] - name = chapterEntry[ChapterTable.name] - } + SChapter.create().apply { + url = chapterEntry[ChapterTable.url] + name = chapterEntry[ChapterTable.name] + } ).awaitSingle() val chapterId = chapterEntry[ChapterTable.id].value @@ -125,16 +138,21 @@ object Chapter { } } + return ChapterDataClass( - chapterEntry[ChapterTable.url], - chapterEntry[ChapterTable.name], - chapterEntry[ChapterTable.date_upload], - chapterEntry[ChapterTable.chapter_number], - chapterEntry[ChapterTable.scanlator], - mangaId, - chapterEntry[ChapterTable.chapterIndex], - chapterCount.toInt(), - pageList.count() + chapterEntry[ChapterTable.url], + chapterEntry[ChapterTable.name], + chapterEntry[ChapterTable.date_upload], + chapterEntry[ChapterTable.chapter_number], + chapterEntry[ChapterTable.scanlator], + mangaId, + chapterEntry[ChapterTable.isRead], + chapterEntry[ChapterTable.isBookmarked], + chapterEntry[ChapterTable.lastPageRead], + + chapterEntry[ChapterTable.chapterIndex], + chapterCount.toInt(), + pageList.count() ) } } diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/backup/legacy/LegacyBackupImport.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/backup/legacy/LegacyBackupImport.kt index 545f885..0366dcf 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/backup/legacy/LegacyBackupImport.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/backup/legacy/LegacyBackupImport.kt @@ -80,11 +80,11 @@ object LegacyBackupImport : LegacyBackupBase() { return validationResult } - private fun restoreCategories(jsonCategories: JsonElement) { // TODO + private fun restoreCategories(jsonCategories: JsonElement) { val backupCategories = parser.fromJson>(jsonCategories) val dbCategories = getCategoryList() - // Iterate over them + // Iterate over them and create missing categories backupCategories.forEach { category -> if (dbCategories.none { it.name == category.name }) { createCategory(category.name) diff --git a/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/ChapterDataClass.kt b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/ChapterDataClass.kt index 9260692..2f68dbb 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/ChapterDataClass.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/model/dataclass/ChapterDataClass.kt @@ -10,12 +10,21 @@ package ir.armor.tachidesk.model.dataclass data class ChapterDataClass( val url: String, val name: String, - val date_upload: Long, - val chapter_number: Float, + val uploadDate: Long, + val chapterNumber: Float, val scanlator: String?, val mangaId: Int, - /** this chapter's index */ + /** chapter is read */ + val read: Boolean, + + /** chapter is bookmarked */ + val bookmarked: Boolean, + + /** last read page, zero means not read/no data */ + val lastPageRead: Int, + + /** this chapter's index, starts with 1 */ val chapterIndex: Int? = null, /** total chapter count, used to calculate if there's a next and prev chapter */