mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-02 18:34:39 -05:00
can serialize Search Filters
This commit is contained in:
@@ -12,7 +12,6 @@ import suwayomi.tachidesk.manga.impl.MangaList
|
|||||||
import suwayomi.tachidesk.manga.impl.Search
|
import suwayomi.tachidesk.manga.impl.Search
|
||||||
import suwayomi.tachidesk.manga.impl.Source
|
import suwayomi.tachidesk.manga.impl.Source
|
||||||
import suwayomi.tachidesk.manga.impl.Source.SourcePreferenceChange
|
import suwayomi.tachidesk.manga.impl.Source.SourcePreferenceChange
|
||||||
import suwayomi.tachidesk.server.JavalinSetup
|
|
||||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||||
|
|
||||||
object SourceController {
|
object SourceController {
|
||||||
@@ -63,9 +62,11 @@ object SourceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** fetch filters of source with id `sourceId` */
|
/** fetch filters of source with id `sourceId` */
|
||||||
fun filters(ctx: Context) { // TODO
|
fun filters(ctx: Context) {
|
||||||
val sourceId = ctx.pathParam("sourceId").toLong()
|
val sourceId = ctx.pathParam("sourceId").toLong()
|
||||||
ctx.json(Search.sourceFilters(sourceId))
|
val reset = ctx.queryParam("reset", "false").toBoolean()
|
||||||
|
|
||||||
|
ctx.json(Search.getInitialFilterList(sourceId, reset))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** single source search */
|
/** single source search */
|
||||||
@@ -73,7 +74,7 @@ object SourceController {
|
|||||||
val sourceId = ctx.pathParam("sourceId").toLong()
|
val sourceId = ctx.pathParam("sourceId").toLong()
|
||||||
val searchTerm = ctx.pathParam("searchTerm")
|
val searchTerm = ctx.pathParam("searchTerm")
|
||||||
val pageNum = ctx.pathParam("pageNum").toInt()
|
val pageNum = ctx.pathParam("pageNum").toInt()
|
||||||
ctx.json(JavalinSetup.future { Search.sourceSearch(sourceId, searchTerm, pageNum) })
|
ctx.json(future { Search.sourceSearch(sourceId, searchTerm, pageNum) })
|
||||||
}
|
}
|
||||||
|
|
||||||
/** all source search */
|
/** all source search */
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ package suwayomi.tachidesk.manga.impl
|
|||||||
* 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 eu.kanade.tachiyomi.source.model.Filter
|
||||||
|
import eu.kanade.tachiyomi.source.model.FilterList
|
||||||
import suwayomi.tachidesk.manga.impl.MangaList.processEntries
|
import suwayomi.tachidesk.manga.impl.MangaList.processEntries
|
||||||
import suwayomi.tachidesk.manga.impl.util.GetHttpSource.getHttpSource
|
import suwayomi.tachidesk.manga.impl.util.GetHttpSource.getHttpSource
|
||||||
import suwayomi.tachidesk.manga.impl.util.lang.awaitSingle
|
import suwayomi.tachidesk.manga.impl.util.lang.awaitSingle
|
||||||
@@ -15,28 +17,53 @@ import suwayomi.tachidesk.manga.model.dataclass.PagedMangaListDataClass
|
|||||||
object Search {
|
object Search {
|
||||||
suspend fun sourceSearch(sourceId: Long, searchTerm: String, pageNum: Int): PagedMangaListDataClass {
|
suspend fun sourceSearch(sourceId: Long, searchTerm: String, pageNum: Int): PagedMangaListDataClass {
|
||||||
val source = getHttpSource(sourceId)
|
val source = getHttpSource(sourceId)
|
||||||
val searchManga = source.fetchSearchManga(pageNum, searchTerm, source.getFilterList()).awaitSingle()
|
val searchManga = source.fetchSearchManga(pageNum, searchTerm, getFilterListOf(sourceId)).awaitSingle()
|
||||||
return searchManga.processEntries(sourceId)
|
return searchManga.processEntries(sourceId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
private val filterListCache = mutableMapOf<Long, FilterList>()
|
||||||
@Suppress("UNUSED_PARAMETER", "UNUSED_VARIABLE")
|
|
||||||
fun sourceFilters(sourceId: Long) {
|
private fun getFilterListOf(sourceId: Long, reset: Boolean = false): FilterList {
|
||||||
val source = getHttpSource(sourceId)
|
if (reset || !filterListCache.containsKey(sourceId)) {
|
||||||
// source.getFilterList().toItems()
|
filterListCache[sourceId] = getHttpSource(sourceId).getFilterList()
|
||||||
|
}
|
||||||
|
return filterListCache[sourceId]!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getInitialFilterList(sourceId: Long, reset: Boolean): List<FilterObject> {
|
||||||
|
return getFilterListOf(sourceId, reset).list.map {
|
||||||
|
FilterObject(
|
||||||
|
when (it) {
|
||||||
|
is Filter.Header -> "Header"
|
||||||
|
is Filter.Separator -> "Separator"
|
||||||
|
is Filter.CheckBox -> "CheckBox"
|
||||||
|
is Filter.TriState -> "TriState"
|
||||||
|
is Filter.Text -> "Text"
|
||||||
|
is Filter.Select<*> -> "Select"
|
||||||
|
is Filter.Group<*> -> "Group"
|
||||||
|
is Filter.Sort -> "Sort"
|
||||||
|
},
|
||||||
|
// when (it) {
|
||||||
|
// is Filter.Select<*> -> it.getValuesType()
|
||||||
|
// else -> null
|
||||||
|
// },
|
||||||
|
it
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// private fun Filter.Select<*>.getValuesType(): String = values::class.java.componentType!!.simpleName
|
||||||
|
|
||||||
|
data class FilterObject(
|
||||||
|
val type: String,
|
||||||
|
val filter: Filter<*>
|
||||||
|
)
|
||||||
|
|
||||||
@Suppress("UNUSED_PARAMETER")
|
@Suppress("UNUSED_PARAMETER")
|
||||||
fun sourceGlobalSearch(searchTerm: String) {
|
fun sourceGlobalSearch(searchTerm: String) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("unused")
|
|
||||||
data class FilterWrapper(
|
|
||||||
val type: String,
|
|
||||||
val filter: Any
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note: Exhentai had a filter serializer (now in SY) that we might be able to steal
|
* Note: Exhentai had a filter serializer (now in SY) that we might be able to steal
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user