From 9fa17f617e497efa437f652cc7ee8139dffe2b91 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Wed, 11 Aug 2021 08:47:07 +0430 Subject: [PATCH] add anime seach functionality --- server/build.gradle.kts | 2 +- .../suwayomi/tachidesk/anime/AnimeAPI.kt | 15 ++++++------- .../suwayomi/tachidesk/anime/impl/Search.kt | 21 +++++++++++++++++++ .../suwayomi/tachidesk/manga/impl/Search.kt | 12 +++++------ 4 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 server/src/main/kotlin/suwayomi/tachidesk/anime/impl/Search.kt diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 819318dd..e7a1ac61 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -102,7 +102,7 @@ sourceSets { // should be bumped with each stable release val tachideskVersion = System.getenv("ProductVersion") ?: "v0.4.5" -val webUIRevisionTag = System.getenv("WebUIRevision") ?: "r23" +val webUIRevisionTag = System.getenv("WebUIRevision") ?: "r24" // counts commit count on master val tachideskRevision = runCatching { diff --git a/server/src/main/kotlin/suwayomi/tachidesk/anime/AnimeAPI.kt b/server/src/main/kotlin/suwayomi/tachidesk/anime/AnimeAPI.kt index 2deb497d..665c1f22 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/anime/AnimeAPI.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/anime/AnimeAPI.kt @@ -14,6 +14,7 @@ import suwayomi.tachidesk.anime.impl.AnimeList.getAnimeList import suwayomi.tachidesk.anime.impl.Episode.getEpisode import suwayomi.tachidesk.anime.impl.Episode.getEpisodeList import suwayomi.tachidesk.anime.impl.Episode.modifyEpisode +import suwayomi.tachidesk.anime.impl.Search.sourceSearch import suwayomi.tachidesk.anime.impl.Source.getAnimeSource import suwayomi.tachidesk.anime.impl.Source.getSourceList import suwayomi.tachidesk.anime.impl.extension.Extension.getExtensionIcon @@ -219,13 +220,13 @@ object AnimeAPI { // ctx.json(sourceGlobalSearch(searchTerm)) // } // -// // single source search -// app.get("/api/v1/source/:sourceId/search/:searchTerm/:pageNum") { ctx -> -// val sourceId = ctx.pathParam("sourceId").toLong() -// val searchTerm = ctx.pathParam("searchTerm") -// val pageNum = ctx.pathParam("pageNum").toInt() -// ctx.json(JavalinSetup.future { sourceSearch(sourceId, searchTerm, pageNum) }) -// } + // single source search + app.get("/api/v1/anime/source/:sourceId/search/:searchTerm/:pageNum") { ctx -> + val sourceId = ctx.pathParam("sourceId").toLong() + val searchTerm = ctx.pathParam("searchTerm") + val pageNum = ctx.pathParam("pageNum").toInt() + ctx.json(future { sourceSearch(sourceId, searchTerm, pageNum) }) + } // // // source filter list // app.get("/api/v1/source/:sourceId/filters/") { ctx -> diff --git a/server/src/main/kotlin/suwayomi/tachidesk/anime/impl/Search.kt b/server/src/main/kotlin/suwayomi/tachidesk/anime/impl/Search.kt new file mode 100644 index 00000000..8f1ff79a --- /dev/null +++ b/server/src/main/kotlin/suwayomi/tachidesk/anime/impl/Search.kt @@ -0,0 +1,21 @@ +package suwayomi.tachidesk.anime.impl + +/* + * 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 suwayomi.tachidesk.anime.impl.AnimeList.processEntries +import suwayomi.tachidesk.anime.impl.util.GetAnimeHttpSource.getAnimeHttpSource +import suwayomi.tachidesk.anime.model.dataclass.PagedAnimeListDataClass +import suwayomi.tachidesk.manga.impl.util.lang.awaitSingle + +object Search { + suspend fun sourceSearch(sourceId: Long, searchTerm: String, pageNum: Int): PagedAnimeListDataClass { + val source = getAnimeHttpSource(sourceId) + val searchManga = source.fetchSearchAnime(pageNum, searchTerm, source.getFilterList()).awaitSingle() + return searchManga.processEntries(sourceId) + } +} diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Search.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Search.kt index c36436f1..1a258415 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Search.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Search.kt @@ -13,18 +13,18 @@ import suwayomi.tachidesk.manga.impl.util.lang.awaitSingle import suwayomi.tachidesk.manga.model.dataclass.PagedMangaListDataClass object Search { - // TODO - fun sourceFilters(sourceId: Long) { - val source = getHttpSource(sourceId) - // source.getFilterList().toItems() - } - suspend fun sourceSearch(sourceId: Long, searchTerm: String, pageNum: Int): PagedMangaListDataClass { val source = getHttpSource(sourceId) val searchManga = source.fetchSearchManga(pageNum, searchTerm, source.getFilterList()).awaitSingle() return searchManga.processEntries(sourceId) } + // TODO + fun sourceFilters(sourceId: Long) { + val source = getHttpSource(sourceId) + // source.getFilterList().toItems() + } + fun sourceGlobalSearch(searchTerm: String) { // TODO }