mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-01 09:54:34 -05:00
add ability to delete downloaded chapters
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user