add ability to delete downloaded chapters

This commit is contained in:
Aria Moradi
2021-09-17 01:29:42 +04:30
parent 4e72a3886f
commit 6bc19af041
5 changed files with 38 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
# Server: v0.5.0-r911 + WebUI: r789
# Server: v0.5.0-r918 + WebUI: r791
## TL;DR
<!-- TODO: fill before release -->
@@ -6,6 +6,7 @@
### Public API
#### Non-breaking changes
- (r915) add BasicAuth support
- (r918) add ability to delete downloaded chapters
#### Breaking changes
- N/A
@@ -21,7 +22,8 @@
## Tachidesk-WebUI
#### Visible changes
- N/A
- (r790) nice looking progress percentage
- (r791) show a Delete button for downloaded chapters
#### Bug fixes
- N/A

View File

@@ -14,7 +14,7 @@ const val MainClass = "suwayomi.tachidesk.MainKt"
// should be bumped with each stable release
val tachideskVersion = System.getenv("ProductVersion") ?: "v0.5.0"
val webUIRevisionTag = System.getenv("WebUIRevision") ?: "r789"
val webUIRevisionTag = System.getenv("WebUIRevision") ?: "r791"
// counts commits on the master branch
val tachideskRevision = runCatching {

View File

@@ -65,6 +65,7 @@ object MangaAPI {
get("{mangaId}/chapters", MangaController::chapterList)
get("{mangaId}/chapter/{chapterIndex}", MangaController::chapterRetrieve)
patch("{mangaId}/chapter/{chapterIndex}", MangaController::chapterModify)
delete("{mangaId}/chapter/{chapterIndex}", MangaController::chapterDelete)
patch("{mangaId}/chapter/{chapterIndex}/meta", MangaController::chapterMeta)

View File

@@ -124,6 +124,16 @@ object MangaController {
ctx.status(200)
}
/** delete a downloaded chapter */
fun chapterDelete(ctx: Context) {
val chapterIndex = ctx.pathParam("chapterIndex").toInt()
val mangaId = ctx.pathParam("mangaId").toInt()
Chapter.deleteChapter(mangaId, chapterIndex)
ctx.status(200)
}
/** used to modify a chapter's meta parameters */
fun chapterMeta(ctx: Context) {
val chapterIndex = ctx.pathParam("chapterIndex").toInt()

View File

@@ -18,6 +18,7 @@ import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update
import suwayomi.tachidesk.manga.impl.Manga.getManga
import suwayomi.tachidesk.manga.impl.Page.getChapterDir
import suwayomi.tachidesk.manga.impl.Page.getPageName
import suwayomi.tachidesk.manga.impl.util.GetHttpSource.getHttpSource
import suwayomi.tachidesk.manga.impl.util.lang.awaitSingle
@@ -28,6 +29,7 @@ import suwayomi.tachidesk.manga.model.table.ChapterTable
import suwayomi.tachidesk.manga.model.table.MangaTable
import suwayomi.tachidesk.manga.model.table.PageTable
import suwayomi.tachidesk.manga.model.table.toDataClass
import java.io.File
import java.time.Instant
object Chapter {
@@ -267,16 +269,16 @@ object Chapter {
fun modifyChapterMeta(mangaId: Int, chapterIndex: Int, key: String, value: String) {
transaction {
val chapter =
val chapterId =
ChapterTable.select { (ChapterTable.manga eq mangaId) and (ChapterTable.chapterIndex eq chapterIndex) }
.first()[ChapterTable.id]
.first()[ChapterTable.id].value
val meta =
transaction { ChapterMetaTable.select { (ChapterMetaTable.ref eq chapter) and (ChapterMetaTable.key eq key) } }.firstOrNull()
transaction { ChapterMetaTable.select { (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) } }.firstOrNull()
if (meta == null) {
ChapterMetaTable.insert {
it[ChapterMetaTable.key] = key
it[ChapterMetaTable.value] = value
it[ChapterMetaTable.ref] = chapter
it[ChapterMetaTable.ref] = chapterId
}
} else {
ChapterMetaTable.update {
@@ -285,4 +287,20 @@ object Chapter {
}
}
}
fun deleteChapter(mangaId: Int, chapterIndex: Int) {
transaction {
val chapterId =
ChapterTable.select { (ChapterTable.manga eq mangaId) and (ChapterTable.chapterIndex eq chapterIndex) }
.first()[ChapterTable.id].value
val chapterDir = getChapterDir(mangaId, chapterId)
File(chapterDir).deleteRecursively()
ChapterTable.update({ (ChapterTable.manga eq mangaId) and (ChapterTable.chapterIndex eq chapterIndex) }) {
it[isDownloaded] = false
}
}
}
}