mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-10 06:42:07 +01:00
fix filterlist bugs (#306)
This commit is contained in:
@@ -7,8 +7,12 @@ package suwayomi.tachidesk.manga.controller
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.exc.MismatchedInputException
|
|
||||||
import io.javalin.http.Context
|
import io.javalin.http.Context
|
||||||
|
import kotlinx.serialization.decodeFromString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import org.kodein.di.DI
|
||||||
|
import org.kodein.di.conf.global
|
||||||
|
import org.kodein.di.instance
|
||||||
import suwayomi.tachidesk.manga.impl.MangaList
|
import suwayomi.tachidesk.manga.impl.MangaList
|
||||||
import suwayomi.tachidesk.manga.impl.Search
|
import suwayomi.tachidesk.manga.impl.Search
|
||||||
import suwayomi.tachidesk.manga.impl.Search.FilterChange
|
import suwayomi.tachidesk.manga.impl.Search.FilterChange
|
||||||
@@ -70,13 +74,15 @@ object SourceController {
|
|||||||
ctx.json(Search.getFilterList(sourceId, reset))
|
ctx.json(Search.getFilterList(sourceId, reset))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val json by DI.global.instance<Json>()
|
||||||
|
|
||||||
/** change filters of source with id `sourceId` */
|
/** change filters of source with id `sourceId` */
|
||||||
fun setFilters(ctx: Context) {
|
fun setFilters(ctx: Context) {
|
||||||
val sourceId = ctx.pathParam("sourceId").toLong()
|
val sourceId = ctx.pathParam("sourceId").toLong()
|
||||||
val filterChange = try {
|
val filterChange = try {
|
||||||
ctx.bodyAsClass<List<FilterChange>>()
|
json.decodeFromString<List<FilterChange>>(ctx.body())
|
||||||
} catch (e: MismatchedInputException) {
|
} catch (e: Exception) {
|
||||||
listOf(ctx.bodyAsClass<FilterChange>())
|
listOf(json.decodeFromString<FilterChange>(ctx.body()))
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.json(Search.setFilter(sourceId, filterChange))
|
ctx.json(Search.setFilter(sourceId, filterChange))
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.source.CatalogueSource
|
|||||||
import eu.kanade.tachiyomi.source.model.Filter
|
import eu.kanade.tachiyomi.source.model.Filter
|
||||||
import eu.kanade.tachiyomi.source.model.FilterList
|
import eu.kanade.tachiyomi.source.model.FilterList
|
||||||
import io.javalin.plugin.json.JsonMapper
|
import io.javalin.plugin.json.JsonMapper
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
import org.kodein.di.DI
|
import org.kodein.di.DI
|
||||||
import org.kodein.di.conf.global
|
import org.kodein.di.conf.global
|
||||||
import org.kodein.di.instance
|
import org.kodein.di.instance
|
||||||
@@ -115,6 +116,7 @@ object Search {
|
|||||||
|
|
||||||
private val jsonMapper by DI.global.instance<JsonMapper>()
|
private val jsonMapper by DI.global.instance<JsonMapper>()
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class FilterChange(
|
data class FilterChange(
|
||||||
val position: Int,
|
val position: Int,
|
||||||
val state: String
|
val state: String
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.App
|
|||||||
import eu.kanade.tachiyomi.source.local.LocalSource
|
import eu.kanade.tachiyomi.source.local.LocalSource
|
||||||
import io.javalin.plugin.json.JavalinJackson
|
import io.javalin.plugin.json.JavalinJackson
|
||||||
import io.javalin.plugin.json.JsonMapper
|
import io.javalin.plugin.json.JsonMapper
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import org.kodein.di.DI
|
import org.kodein.di.DI
|
||||||
import org.kodein.di.bind
|
import org.kodein.di.bind
|
||||||
@@ -59,6 +60,7 @@ fun applicationSetup() {
|
|||||||
bind<ApplicationDirs>() with singleton { applicationDirs }
|
bind<ApplicationDirs>() with singleton { applicationDirs }
|
||||||
bind<IUpdater>() with singleton { Updater() }
|
bind<IUpdater>() with singleton { Updater() }
|
||||||
bind<JsonMapper>() with singleton { JavalinJackson() }
|
bind<JsonMapper>() with singleton { JavalinJackson() }
|
||||||
|
bind<Json>() with singleton { Json { ignoreUnknownKeys = true } }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user