Skip to content

Commit

Permalink
fix filterlist bugs (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriaMoradi authored Mar 4, 2022
1 parent 05513bf commit 8fb1a0b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ package suwayomi.tachidesk.manga.controller
* 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 com.fasterxml.jackson.databind.exc.MismatchedInputException
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.Search
import suwayomi.tachidesk.manga.impl.Search.FilterChange
Expand Down Expand Up @@ -70,13 +74,15 @@ object SourceController {
ctx.json(Search.getFilterList(sourceId, reset))
}

private val json by DI.global.instance<Json>()

/** change filters of source with id `sourceId` */
fun setFilters(ctx: Context) {
val sourceId = ctx.pathParam("sourceId").toLong()
val filterChange = try {
ctx.bodyAsClass<List<FilterChange>>()
} catch (e: MismatchedInputException) {
listOf(ctx.bodyAsClass<FilterChange>())
json.decodeFromString<List<FilterChange>>(ctx.body())
} catch (e: Exception) {
listOf(json.decodeFromString<FilterChange>(ctx.body()))
}

ctx.json(Search.setFilter(sourceId, filterChange))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList
import io.javalin.plugin.json.JsonMapper
import kotlinx.serialization.Serializable
import org.kodein.di.DI
import org.kodein.di.conf.global
import org.kodein.di.instance
Expand Down Expand Up @@ -115,6 +116,7 @@ object Search {

private val jsonMapper by DI.global.instance<JsonMapper>()

@Serializable
data class FilterChange(
val position: Int,
val state: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.App
import eu.kanade.tachiyomi.source.local.LocalSource
import io.javalin.plugin.json.JavalinJackson
import io.javalin.plugin.json.JsonMapper
import kotlinx.serialization.json.Json
import mu.KotlinLogging
import org.kodein.di.DI
import org.kodein.di.bind
Expand Down Expand Up @@ -59,6 +60,7 @@ fun applicationSetup() {
bind<ApplicationDirs>() with singleton { applicationDirs }
bind<IUpdater>() with singleton { Updater() }
bind<JsonMapper>() with singleton { JavalinJackson() }
bind<Json>() with singleton { Json { ignoreUnknownKeys = true } }
}
)

Expand Down

0 comments on commit 8fb1a0b

Please sign in to comment.