From c20078547942e67e049bab5b028906e7719a95a8 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Tue, 11 May 2021 18:45:53 +0430 Subject: [PATCH] handle front, handle orphans --- .../main/kotlin/ir/armor/tachidesk/impl/Chapter.kt | 14 ++++++++++---- webUI/react/src/components/ChapterCard.tsx | 4 ++-- webUI/react/src/typings.d.ts | 7 +++++-- 3 files changed, 17 insertions(+), 8 deletions(-) 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 c0b7c2b..aafa292 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Chapter.kt @@ -17,6 +17,7 @@ import ir.armor.tachidesk.model.database.table.MangaTable import ir.armor.tachidesk.model.database.table.PageTable import ir.armor.tachidesk.model.dataclass.ChapterDataClass import org.jetbrains.exposed.sql.and +import org.jetbrains.exposed.sql.deleteWhere import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.selectAll @@ -69,16 +70,22 @@ 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 dbChapterList = transaction { ChapterTable.selectAll() } + dbChapterList.forEach { + (it[ChapterTable.chapterIndex] >= chapterList.size + || chapterList[it[ChapterTable.chapterIndex]].url != it[ChapterTable.url]) + + ChapterTable.deleteWhere { ChapterTable.id eq it[ChapterTable.id] } + } } - val dbChapters = transaction { ChapterTable.selectAll() } + val dbChapterMap = transaction { ChapterTable.selectAll() } .associateBy({ it[ChapterTable.url] }, { it }) chapterList.mapIndexed { index, it -> - val dbChapter = dbChapters.getValue(it.url) + val dbChapter = dbChapterMap.getValue(it.url) ChapterDataClass( it.url, @@ -138,7 +145,6 @@ object Chapter { } } - return ChapterDataClass( chapterEntry[ChapterTable.url], chapterEntry[ChapterTable.name], diff --git a/webUI/react/src/components/ChapterCard.tsx b/webUI/react/src/components/ChapterCard.tsx index 7521386..ce311bd 100644 --- a/webUI/react/src/components/ChapterCard.tsx +++ b/webUI/react/src/components/ChapterCard.tsx @@ -49,7 +49,7 @@ export default function ChapterCard(props: IProps) { const history = useHistory(); const { chapter } = props; - const dateStr = chapter.date_upload && new Date(chapter.date_upload).toISOString().slice(0, 10); + const dateStr = chapter.uploadDate && new Date(chapter.uploadDate).toISOString().slice(0, 10); return ( <> @@ -60,7 +60,7 @@ export default function ChapterCard(props: IProps) {
{chapter.name} - {chapter.chapter_number > 0 && ` : ${chapter.chapter_number}`} + {chapter.chapterNumber > 0 && ` : ${chapter.chapterNumber}`} {chapter.scanlator} diff --git a/webUI/react/src/typings.d.ts b/webUI/react/src/typings.d.ts index 747f267..426e066 100644 --- a/webUI/react/src/typings.d.ts +++ b/webUI/react/src/typings.d.ts @@ -56,10 +56,13 @@ interface IChapter { id: number url: string name: string - date_upload: number - chapter_number: number + uploadDate: number + chapterNumber: number scanlator: String mangaId: number + read: boolean + bookmarked: boolean + lastPageRead: number chapterIndex: number chapterCount: number pageCount: number