mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-16 17:24:07 -05:00
add category and global meta (#438)
This commit is contained in:
@@ -86,6 +86,8 @@ object MangaAPI {
|
||||
get("{categoryId}", CategoryController.categoryMangas)
|
||||
patch("{categoryId}", CategoryController.categoryModify)
|
||||
delete("{categoryId}", CategoryController.categoryDelete)
|
||||
|
||||
patch("{categoryId}/meta", CategoryController.meta)
|
||||
}
|
||||
|
||||
path("backup") {
|
||||
|
||||
@@ -129,4 +129,25 @@ object CategoryController {
|
||||
httpCode(HttpCode.OK)
|
||||
}
|
||||
)
|
||||
|
||||
/** used to modify a category's meta parameters */
|
||||
val meta = handler(
|
||||
pathParam<Int>("categoryId"),
|
||||
formParam<String>("key"),
|
||||
formParam<String>("value"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("Add meta data to category")
|
||||
description("A simple Key-Value storage in the manga object, you can set values for whatever you want inside it.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, categoryId, key, value ->
|
||||
Category.modifyMeta(categoryId, key, value)
|
||||
ctx.status(200)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpCode.OK)
|
||||
httpCode(HttpCode.NOT_FOUND)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.jetbrains.exposed.sql.SortOrder
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.and
|
||||
import org.jetbrains.exposed.sql.deleteWhere
|
||||
import org.jetbrains.exposed.sql.insert
|
||||
import org.jetbrains.exposed.sql.insertAndGetId
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
@@ -20,6 +21,7 @@ import suwayomi.tachidesk.manga.impl.CategoryManga.removeMangaFromCategory
|
||||
import suwayomi.tachidesk.manga.impl.util.lang.isNotEmpty
|
||||
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMetaTable
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.toDataClass
|
||||
@@ -120,4 +122,31 @@ object Category {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getCategoryMetaMap(categoryId: Int): Map<String, String> {
|
||||
return transaction {
|
||||
CategoryMetaTable.select { CategoryMetaTable.ref eq categoryId }
|
||||
.associate { it[CategoryMetaTable.key] to it[CategoryMetaTable.value] }
|
||||
}
|
||||
}
|
||||
|
||||
fun modifyMeta(categoryId: Int, key: String, value: String) {
|
||||
transaction {
|
||||
val meta = transaction {
|
||||
CategoryMetaTable.select { (CategoryMetaTable.ref eq categoryId) and (CategoryMetaTable.key eq key) }
|
||||
}.firstOrNull()
|
||||
|
||||
if (meta == null) {
|
||||
CategoryMetaTable.insert {
|
||||
it[CategoryMetaTable.key] = key
|
||||
it[CategoryMetaTable.value] = value
|
||||
it[CategoryMetaTable.ref] = categoryId
|
||||
}
|
||||
} else {
|
||||
CategoryMetaTable.update({ (CategoryMetaTable.ref eq categoryId) and (CategoryMetaTable.key eq key) }) {
|
||||
it[CategoryMetaTable.value] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,9 +219,9 @@ object Chapter {
|
||||
val chapterId =
|
||||
ChapterTable.select { (ChapterTable.manga eq mangaId) and (ChapterTable.sourceOrder eq chapterIndex) }
|
||||
.first()[ChapterTable.id].value
|
||||
val meta = transaction {
|
||||
val meta =
|
||||
ChapterMetaTable.select { (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) }
|
||||
}.firstOrNull()
|
||||
.firstOrNull()
|
||||
|
||||
if (meta == null) {
|
||||
ChapterMetaTable.insert {
|
||||
|
||||
@@ -152,29 +152,27 @@ object Manga {
|
||||
false
|
||||
)
|
||||
|
||||
fun getMangaMetaMap(manga: Int): Map<String, String> {
|
||||
fun getMangaMetaMap(mangaId: Int): Map<String, String> {
|
||||
return transaction {
|
||||
MangaMetaTable.select { MangaMetaTable.ref eq manga }
|
||||
MangaMetaTable.select { MangaMetaTable.ref eq mangaId }
|
||||
.associate { it[MangaMetaTable.key] to it[MangaMetaTable.value] }
|
||||
}
|
||||
}
|
||||
|
||||
fun modifyMangaMeta(mangaId: Int, key: String, value: String) {
|
||||
transaction {
|
||||
val manga = MangaTable.select { MangaTable.id eq mangaId }
|
||||
.first()[MangaTable.id]
|
||||
val meta = transaction {
|
||||
MangaMetaTable.select { (MangaMetaTable.ref eq manga) and (MangaMetaTable.key eq key) }
|
||||
}.firstOrNull()
|
||||
val meta =
|
||||
MangaMetaTable.select { (MangaMetaTable.ref eq mangaId) and (MangaMetaTable.key eq key) }
|
||||
.firstOrNull()
|
||||
|
||||
if (meta == null) {
|
||||
MangaMetaTable.insert {
|
||||
it[MangaMetaTable.key] = key
|
||||
it[MangaMetaTable.value] = value
|
||||
it[MangaMetaTable.ref] = manga
|
||||
it[MangaMetaTable.ref] = mangaId
|
||||
}
|
||||
} else {
|
||||
MangaMetaTable.update({ (MangaMetaTable.ref eq manga) and (MangaMetaTable.key eq key) }) {
|
||||
MangaMetaTable.update({ (MangaMetaTable.ref eq mangaId) and (MangaMetaTable.key eq key) }) {
|
||||
it[MangaMetaTable.value] = value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,5 +11,6 @@ data class CategoryDataClass(
|
||||
val id: Int,
|
||||
val order: Int,
|
||||
val name: String,
|
||||
val default: Boolean
|
||||
val default: Boolean,
|
||||
val meta: Map<String, String> = emptyMap()
|
||||
)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package suwayomi.tachidesk.manga.model.table
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.sql.ReferenceOption
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMetaTable.ref
|
||||
|
||||
/**
|
||||
* Metadata storage for clients, about Chapter with id == [ref].
|
||||
*/
|
||||
object CategoryMetaTable : IntIdTable() {
|
||||
val key = varchar("key", 256)
|
||||
val value = varchar("value", 4096)
|
||||
val ref = reference("category_ref", CategoryTable, ReferenceOption.CASCADE)
|
||||
}
|
||||
@@ -9,6 +9,7 @@ package suwayomi.tachidesk.manga.model.table
|
||||
|
||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.sql.ResultRow
|
||||
import suwayomi.tachidesk.manga.impl.Category
|
||||
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
|
||||
|
||||
object CategoryTable : IntIdTable() {
|
||||
@@ -18,8 +19,9 @@ object CategoryTable : IntIdTable() {
|
||||
}
|
||||
|
||||
fun CategoryTable.toDataClass(categoryEntry: ResultRow) = CategoryDataClass(
|
||||
categoryEntry[this.id].value,
|
||||
categoryEntry[id].value,
|
||||
categoryEntry[order],
|
||||
categoryEntry[name],
|
||||
categoryEntry[isDefault]
|
||||
categoryEntry[isDefault],
|
||||
Category.getCategoryMetaMap(categoryEntry[id].value)
|
||||
)
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.jetbrains.exposed.sql.ReferenceOption
|
||||
import suwayomi.tachidesk.manga.model.table.ChapterMetaTable.ref
|
||||
|
||||
/**
|
||||
* Meta data storage for clients, about Chapter with id == [ref].
|
||||
* Metadata storage for clients, about Chapter with id == [ref].
|
||||
*
|
||||
* For example, if you added reader mode(with the key juiReaderMode) such as webtoon to a manga object,
|
||||
* this is what will show up when you request that manga from the api again
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.jetbrains.exposed.sql.ReferenceOption
|
||||
import suwayomi.tachidesk.manga.model.table.MangaMetaTable.ref
|
||||
|
||||
/**
|
||||
* Meta data storage for clients, about Manga with id == [ref].
|
||||
* Metadata storage for clients, about Manga with id == [ref].
|
||||
*
|
||||
* For example, if you added reader mode(with the key juiReaderMode) such as webtoon to a manga object,
|
||||
* this is what will show up when you request that manga from the api again
|
||||
|
||||
Reference in New Issue
Block a user