mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 03:14:40 -05:00
Overhaul OPDS feeds for discovery, filtering, and enhanced UX (#1543)
* fix: correct chapter facets URL to include /chapters endpoint
Update addChapterSortAndFilterFacets to use the correct URL path
from `/manga/{id}` to `/manga/{id}/chapters` for proper routing.
* feat(opds): restructure feeds and add exploration capabilities
This commit completely refactors the OPDS v1.2 implementation to align it more closely with the WebUI experience, separating "Library" browsing from "Explore" functionality.
Key changes include:
- The root feed is now a navigation feed directing to distinct "Library" and "Explore" sections.
- A new "History" feed has been added to the root to show recently read chapters.
- The "Explore" section now allows browsing all available sources, not just those with manga in the library.
- Feeds for exploring a source now support faceting by "Popular" and "Latest", mirroring the WebUI.
- The "Library" section retains all previous browsing methods (by category, genre, status, etc.).
- Facet link generation has been corrected to use the proper base URL, fixing broken navigation in chapter lists.
- The `OpdsFeedBuilder.kt` file has been refactorized into smaller, more manageable helper files (`OpdsEntryBuilder.kt`, `OpdsFeedHelper.kt`) to resolve a `java.lang.OutOfMemoryError: GC overhead limit exceeded` error during compilation.
- All OPDS-related strings (`strings.xml`) have been updated to reflect the new structure and improve clarity.
This new structure provides a much more intuitive and powerful browsing experience for OPDS clients, enabling content discovery in addition to library management.
* feat(opds)!: implement advanced filtering and sorting for library feeds
This commit significantly enhances the OPDS library feeds by introducing advanced sorting and filtering capabilities, mirroring the features available in the WebUI. It also standardizes the terminology from "manga" to "series" across all user-facing OPDS feeds for better clarity and consistency.
Key Features & Changes:
- **Library Facets:** All library feeds (All Series, By Source, By Category, By Genre, etc.) now include OPDS facets for:
- **Sorting:** By title (A-Z, Z-A), last read, latest chapter, date added, and total unread chapters.
- **Filtering:** By content status including unread, downloaded, ongoing, and completed.
- **Terminology Update:** The term "manga" has been replaced with "series" in all user-facing OPDS titles, descriptions, and endpoints to align with the frontend terminology.
- **Code Refactoring:**
- `MangaRepository` has been updated with the correct Exposed SQL syntax (`Case`/`sum` for conditional counts, `having` clause for filtering on aggregates) to support the new facets.
- `OpdsEntryBuilder` now includes a new function `addLibraryMangaSortAndFilterFacets` to generate the facet links.
- `OpdsV1Controller` and `OpdsFeedBuilder` have been updated to handle the new `sort` and `filter` parameters and to call the new facet generation logic.
BREAKING CHANGE: The API endpoints for manga have been renamed to use 'series'. Any client implementation will need to update its routes.
For example, `/api/opds/v1.2/manga/{id}/chapters` is now `/api/opds/v1.2/series/{id}/chapters`.
* feat(opds): add item counts (thr:count) to navigation and facet links
This change enhances the OPDS feeds by including the number of items for various navigation links and filter facets, adhering to the OPDS 1.2 specification.
The `thr:count` attribute provides a hint to clients about the number of entries in a linked feed, significantly improving the user experience by showing counts upfront.
- Navigation Feeds (Categories, Sources, Genres, Statuses, Languages) now display the total number of manga for each entry in their respective links.
- Acquisition Feeds for the library and chapters now include counts for their filter facets (e.g., Unread, Downloaded, Completed).
This required updating DTOs to carry count data, modifying repository queries to calculate these counts efficiently, and adjusting the feed builders to include the `thr:count` attribute in the generated XML.
* refactor(opds)!: simplify root feed by removing library sub-level
The OPDS feed navigation was previously nested, requiring users to first select "Library" and then navigate to a subsection like "All Series" or "Categories". This extra step is cumbersome for OPDS clients and complicates the user experience.
This change elevates all library-related navigation entries directly to the root feed, flattening the hierarchy and making content more accessible.
As part of this refactoring:
- The `getLibraryFeed` builder and its corresponding controller/API endpoints have been removed.
- Unused string resources for the "Library" entry have been deleted.
BREAKING CHANGE: The `/api/opds/v1.2/library` endpoint has been removed. Clients should now discover library sections directly from the root feed at `/api/opds/v1.2`.
* feat(opds): enhance feeds with comprehensive manga and chapter details
This commit significantly enriches the OPDS feeds to provide a more detailed and compliant user experience.
- Refactored `OpdsMangaAcqEntry` and `OpdsChapterMetadataAcqEntry` to include additional fields such as status, source information, author, description, and web URLs.
- The OPDS entry builder (`OpdsEntryBuilder`) now populates entries with this richer metadata, including summaries, content descriptions, authors, and categories, aligning more closely with the OPDS Catalog specification.
- Added OPDS constants for 'popular' and 'new' sort relations to align with the specification.
- Included "alternate" links for both manga and chapters, allowing clients to open the item on its source website ("View on web").
- Updated internationalization strings and constants to support the new features and metadata.
* fix(opds): fetch chapters for non-library manga in feed
Previously, when accessing the OPDS chapter feed for a manga discovered via the "Explore" feature (and thus not yet in the library), the feed would be empty. This was because the feed generation logic only queried the local database, which had no chapter entries for these manga.
This commit resolves the issue by modifying `getSeriesChaptersFeed` to be a suspend function. It now implements a fallback mechanism:
- It first attempts to load chapters from the local database.
- If no chapters are found, it triggers an online fetch from the source to populate the database.
- It then re-queries the local data to build the complete chapter feed.
This ensures that chapter lists are correctly displayed for all manga, whether they are in the library or being explored for the first time.
Additionally, this commit includes a minor correction to the URN identifier for the root feed to better align with its path.
* feat(opds): provide direct stream and acquisition links when page count is known
Previously, the OPDS chapter feed always provided a single link to a separate metadata feed for each chapter. This was done to defer the costly operation of fetching the page count for undownloaded chapters, ensuring the main chapter list loaded quickly.
This commit introduces a more efficient, conditional approach. If a chapter's page count is already known (e.g., because it's downloaded or has been previously fetched), the chapter feed entry now includes direct links for:
- OPDS-PSE page streaming (`pse:stream`).
- CBZ file acquisition (`acquisition/open-access`).
- Chapter cover image (`image`).
If the page count is not known, the entry falls back to the previous behavior, linking to the metadata feed to perform the page count lookup on-demand.
This significantly improves the user experience for OPDS clients by reducing the number of requests needed to start reading or downloading chapters that are already available on the server, making navigation faster and more fluid.
* fix(opds): resolve suspend calls and add missing lastReadAt for OPDS feeds
The OPDS feed generation was failing to compile due to two main issues:
1. The `OpdsChapterListAcqEntry` DTO was missing the `lastReadAt` property, which is required for the OPDS-PSE `lastReadDate` attribute.
2. Several functions in `OpdsFeedBuilder` were attempting to call the `suspend` function `createChapterListEntry` from a non-coroutine context.
This commit resolves these issues by:
- Adding the `lastReadAt` field to `OpdsChapterListAcqEntry` and populating it correctly from the database in the `ChapterRepository`.
- Refactoring `getHistoryFeed`, `getLibraryUpdatesFeed`, and `getSeriesChaptersFeed` in `OpdsFeedBuilder` to be `suspend` functions.
- Wrapping the entry creation logic in `withContext(Dispatchers.IO)` to provide the necessary coroutine scope for the suspend call and to perform the mapping on a background thread.
* refactor(opds): standardize library feed generation and enhance facets
This commit refactors the OPDS v1.2 feed generation logic to improve code structure, correctness, and feature capability.
The primary changes include:
- A new private `getLibraryFeed` helper function in `OpdsV1Controller` has been introduced to centralize and DRY up the logic for creating library-specific acquisition feeds.
- A new `OpdsMangaFilter` DTO now encapsulates all filtering, sorting, and pagination parameters, simplifying the controller handlers and making them more maintainable.
- URL generation for category, genre, status, and language feeds has been corrected. Links now correctly point to root-level paths (e.g., `/opds/v1.2/genre/{name}`) instead of being incorrectly nested under `/library/`.
- The OPDS facet system is enhanced with more specific facet groups and "All" links for a better user experience when clearing filters.
Associated changes:
- i18n strings in `strings.xml` have been reorganized with comments and new strings have been added to support the enhanced facet groups.
- The route for the publication status feed has been renamed from `/status/{id}` to `/statuses` for consistency.
- KDoc comments have been added and improved throughout the affected files for better code documentation.
* fix(opds): revert direct acquisition links in chapter feeds to improve performance
This reverts commit 33cdc0d534292760a3225cee18e274df542f0778.
The previous change introduced direct stream and download links in chapter list feeds when the page count was known. While convenient, this caused a significant performance degradation on feeds with many chapters, as it required checking for the existence of a CBZ file for every single entry.
This commit restores the original behavior where chapter list entries always link to a dedicated metadata feed. This approach defers expensive I/O operations until a user explicitly requests a single chapter's details, ensuring that chapter list feeds load quickly and efficiently. Direct acquisition and streaming links are now exclusively generated within the metadata feed.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package suwayomi.tachidesk.opds.controller
|
||||
|
||||
import io.javalin.http.Context
|
||||
import io.javalin.http.HttpStatus
|
||||
import suwayomi.tachidesk.i18n.LocalizationHelper
|
||||
import suwayomi.tachidesk.i18n.MR
|
||||
import suwayomi.tachidesk.opds.constants.OpdsConstants
|
||||
import suwayomi.tachidesk.opds.dto.OpdsMangaFilter
|
||||
import suwayomi.tachidesk.opds.dto.OpdsSearchCriteria
|
||||
import suwayomi.tachidesk.opds.dto.PrimaryFilterType
|
||||
import suwayomi.tachidesk.opds.impl.OpdsFeedBuilder
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
import suwayomi.tachidesk.server.util.handler
|
||||
@@ -13,11 +16,42 @@ import suwayomi.tachidesk.server.util.queryParam
|
||||
import suwayomi.tachidesk.server.util.withOperation
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* Controller for handling OPDS v1.2 feed requests.
|
||||
*/
|
||||
object OpdsV1Controller {
|
||||
private const val OPDS_MIME = "application/xml;profile=opds-catalog;charset=UTF-8"
|
||||
private const val BASE_URL = "/api/opds/v1.2"
|
||||
|
||||
// OPDS Catalog Root Feed
|
||||
/**
|
||||
* Helper function to generate and send a library feed response.
|
||||
* It asynchronously builds the feed and sets the response content type.
|
||||
*/
|
||||
private fun getLibraryFeed(
|
||||
ctx: Context,
|
||||
pageNum: Int?,
|
||||
criteria: OpdsMangaFilter,
|
||||
) {
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, ctx.queryParam("lang"))
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getLibraryFeed(
|
||||
criteria = criteria,
|
||||
baseUrl = BASE_URL,
|
||||
pageNum = pageNum ?: 1,
|
||||
sort = criteria.sort,
|
||||
filter = criteria.filter,
|
||||
locale = locale,
|
||||
)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves the root navigation feed for the OPDS catalog.
|
||||
*/
|
||||
val rootFeed =
|
||||
handler(
|
||||
queryParam<String?>("lang"),
|
||||
@@ -28,21 +62,43 @@ object OpdsV1Controller {
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, lang ->
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.contentType(OPDS_MIME).result(OpdsFeedBuilder.getRootFeed(BASE_URL, locale))
|
||||
},
|
||||
withResults = { httpCode(HttpStatus.OK) },
|
||||
)
|
||||
|
||||
// --- Main Navigation Feeds ---
|
||||
|
||||
/**
|
||||
* Serves an acquisition feed listing recently read chapters.
|
||||
*/
|
||||
val historyFeed =
|
||||
handler(
|
||||
queryParam<Int?>("pageNumber"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS History Feed")
|
||||
description("Acquisition feed listing recently read chapters.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, pageNumber, lang ->
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getRootFeed(BASE_URL, locale)
|
||||
OpdsFeedBuilder.getHistoryFeed(BASE_URL, pageNumber ?: 1, locale)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
}
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
},
|
||||
withResults = { httpCode(HttpStatus.OK) },
|
||||
)
|
||||
|
||||
// OPDS Search Description Feed
|
||||
/**
|
||||
* Serves the OpenSearch description document for catalog integration.
|
||||
*/
|
||||
val searchFeed =
|
||||
handler(
|
||||
queryParam<String?>("lang"),
|
||||
@@ -54,7 +110,6 @@ object OpdsV1Controller {
|
||||
},
|
||||
behaviorOf = { ctx, lang ->
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
|
||||
ctx.contentType("application/opensearchdescription+xml").result(
|
||||
"""
|
||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
|
||||
@@ -63,87 +118,117 @@ object OpdsV1Controller {
|
||||
<Description>${MR.strings.opds_search_description.localized(locale)}</Description>
|
||||
<InputEncoding>UTF-8</InputEncoding>
|
||||
<OutputEncoding>UTF-8</OutputEncoding>
|
||||
<Url type="${OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION}"
|
||||
rel="results"
|
||||
template="$BASE_URL/mangas?query={searchTerms}&lang=${locale.toLanguageTag()}"/>
|
||||
<Url type="${OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION}"
|
||||
rel="results"
|
||||
template="$BASE_URL/library/series?query={searchTerms}&lang=${locale.toLanguageTag()}"/>
|
||||
</OpenSearchDescription>
|
||||
""".trimIndent(),
|
||||
)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
},
|
||||
withResults = { httpCode(HttpStatus.OK) },
|
||||
)
|
||||
|
||||
// --- Main Navigation & Broad Acquisition Feeds ---
|
||||
|
||||
// All Mangas / Search Results Feed
|
||||
val mangasFeed =
|
||||
/**
|
||||
* Serves an acquisition feed for all series in the library or search results.
|
||||
* This endpoint handles both general library browsing and specific search queries.
|
||||
*/
|
||||
val seriesFeed =
|
||||
handler(
|
||||
queryParam<Int?>("pageNumber"),
|
||||
queryParam<String?>("query"),
|
||||
queryParam<String?>("author"),
|
||||
queryParam<String?>("title"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Mangas Feed")
|
||||
description(
|
||||
"Provides a list of manga entries. Can be paginated and supports search via query parameters " +
|
||||
"(query, author, title). If search parameters are present, it acts as a search results feed.",
|
||||
documentWith = { withOperation { summary("OPDS Series in Library Feed") } },
|
||||
behaviorOf = { ctx ->
|
||||
val pageNumber = ctx.queryParam("pageNumber")?.toIntOrNull()
|
||||
val query = ctx.queryParam("query")
|
||||
val author = ctx.queryParam("author")
|
||||
val title = ctx.queryParam("title")
|
||||
val lang = ctx.queryParam("lang")
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
|
||||
if (query != null || author != null || title != null) {
|
||||
val opdsSearchCriteria = OpdsSearchCriteria(query, author, title)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getSearchFeed(opdsSearchCriteria, BASE_URL, pageNumber ?: 1, locale)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val criteria =
|
||||
OpdsMangaFilter(
|
||||
sourceId = ctx.queryParam("source_id")?.toLongOrNull(),
|
||||
categoryId = ctx.queryParam("category_id")?.toIntOrNull(),
|
||||
statusId = ctx.queryParam("status_id")?.toIntOrNull(),
|
||||
genre = ctx.queryParam("genre"),
|
||||
langCode = ctx.queryParam("lang_code"),
|
||||
sort = ctx.queryParam("sort"),
|
||||
filter = ctx.queryParam("filter"),
|
||||
primaryFilter = PrimaryFilterType.NONE,
|
||||
)
|
||||
getLibraryFeed(
|
||||
ctx,
|
||||
pageNumber,
|
||||
criteria,
|
||||
)
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, pageNumber, query, author, title, lang ->
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
val opdsSearchCriteria =
|
||||
if (query != null || author != null || title != null) {
|
||||
OpdsSearchCriteria(query, author, title)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val effectivePageNumber = if (opdsSearchCriteria != null) 1 else pageNumber ?: 1
|
||||
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getMangasFeed(opdsSearchCriteria, BASE_URL, effectivePageNumber, locale)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
}
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
},
|
||||
withResults = { httpCode(HttpStatus.OK) },
|
||||
)
|
||||
|
||||
// Sources Navigation Feed
|
||||
val sourcesFeed =
|
||||
/**
|
||||
* Serves a navigation feed listing all available manga sources for exploration.
|
||||
*/
|
||||
val exploreSourcesFeed =
|
||||
handler(
|
||||
queryParam<Int?>("pageNumber"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Sources Navigation Feed")
|
||||
description("Navigation feed listing available manga sources. Each entry links to a feed for a specific source.")
|
||||
summary("OPDS All Sources Navigation Feed")
|
||||
description("Navigation feed listing all available manga sources.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, pageNumber, lang ->
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getSourcesFeed(BASE_URL, pageNumber ?: 1, locale)
|
||||
OpdsFeedBuilder.getExploreSourcesFeed(BASE_URL, pageNumber ?: 1, locale)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
}
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
},
|
||||
withResults = { httpCode(HttpStatus.OK) },
|
||||
)
|
||||
|
||||
// Categories Navigation Feed
|
||||
/**
|
||||
* Serves a navigation feed listing only the sources for series present in the library.
|
||||
*/
|
||||
val librarySourcesFeed =
|
||||
handler(
|
||||
queryParam<Int?>("pageNumber"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Library Sources Navigation Feed")
|
||||
description("Navigation feed listing sources for series currently in the library.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, pageNumber, lang ->
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getLibrarySourcesFeed(BASE_URL, pageNumber ?: 1, locale)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
}
|
||||
},
|
||||
withResults = { httpCode(HttpStatus.OK) },
|
||||
)
|
||||
|
||||
/**
|
||||
* Serves a navigation feed for browsing manga categories within the library.
|
||||
*/
|
||||
val categoriesFeed =
|
||||
handler(
|
||||
queryParam<Int?>("pageNumber"),
|
||||
@@ -151,7 +236,7 @@ object OpdsV1Controller {
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Categories Navigation Feed")
|
||||
description("Navigation feed listing available manga categories. Each entry links to a feed for a specific category.")
|
||||
description("Navigation feed listing available manga categories for the library.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, pageNumber, lang ->
|
||||
@@ -164,12 +249,12 @@ object OpdsV1Controller {
|
||||
}
|
||||
}
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
},
|
||||
withResults = { httpCode(HttpStatus.OK) },
|
||||
)
|
||||
|
||||
// Genres Navigation Feed
|
||||
/**
|
||||
* Serves a navigation feed for browsing manga genres within the library.
|
||||
*/
|
||||
val genresFeed =
|
||||
handler(
|
||||
queryParam<Int?>("pageNumber"),
|
||||
@@ -177,7 +262,7 @@ object OpdsV1Controller {
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Genres Navigation Feed")
|
||||
description("Navigation feed listing available manga genres. Each entry links to a feed for a specific genre.")
|
||||
description("Navigation feed listing available manga genres in the library.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, pageNumber, lang ->
|
||||
@@ -190,51 +275,44 @@ object OpdsV1Controller {
|
||||
}
|
||||
}
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
},
|
||||
withResults = { httpCode(HttpStatus.OK) },
|
||||
)
|
||||
|
||||
// Status Navigation Feed
|
||||
val statusFeed =
|
||||
/**
|
||||
* Serves a navigation feed for browsing series by their publication status.
|
||||
*/
|
||||
val statusesFeed =
|
||||
handler(
|
||||
queryParam<Int?>("pageNumber"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Status Navigation Feed")
|
||||
description(
|
||||
"Navigation feed listing manga publication statuses. Each entry links to a feed for manga with a specific status.",
|
||||
)
|
||||
summary("OPDS Statuses Navigation Feed")
|
||||
description("Navigation feed listing series publication statuses for the library.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, pageNumber, lang ->
|
||||
behaviorOf = { ctx, lang ->
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
// Ignoramos pageNumber aquí, siempre usamos 1
|
||||
OpdsFeedBuilder.getStatusFeed(BASE_URL, 1, locale)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
}
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
},
|
||||
withResults = { httpCode(HttpStatus.OK) },
|
||||
)
|
||||
|
||||
// Content Languages Navigation Feed
|
||||
/**
|
||||
* Serves a navigation feed for browsing series by their content language.
|
||||
*/
|
||||
val languagesFeed =
|
||||
handler(
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Content Languages Navigation Feed")
|
||||
description(
|
||||
"Navigation feed listing available content languages for manga. " +
|
||||
"Each entry links to a feed for manga in a specific content language.",
|
||||
)
|
||||
description("Navigation feed listing available content languages for series in the library.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, lang ->
|
||||
@@ -247,12 +325,12 @@ object OpdsV1Controller {
|
||||
}
|
||||
}
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
},
|
||||
withResults = { httpCode(HttpStatus.OK) },
|
||||
)
|
||||
|
||||
// Library Updates Acquisition Feed
|
||||
/**
|
||||
* Serves an acquisition feed of recent chapter updates for series in the library.
|
||||
*/
|
||||
val libraryUpdatesFeed =
|
||||
handler(
|
||||
queryParam<Int?>("pageNumber"),
|
||||
@@ -260,7 +338,7 @@ object OpdsV1Controller {
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Library Updates Feed")
|
||||
description("Acquisition feed listing recent chapter updates for manga in the library. Supports pagination.")
|
||||
description("Acquisition feed listing recent chapter updates for series in the library.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, pageNumber, lang ->
|
||||
@@ -273,30 +351,29 @@ object OpdsV1Controller {
|
||||
}
|
||||
}
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
},
|
||||
withResults = { httpCode(HttpStatus.OK) },
|
||||
)
|
||||
|
||||
// --- Filtered Acquisition Feeds ---
|
||||
|
||||
// Source-Specific Manga Acquisition Feed
|
||||
val sourceFeed =
|
||||
/**
|
||||
* Serves an acquisition feed for all series from a specific source.
|
||||
*/
|
||||
val exploreSourceFeed =
|
||||
handler(
|
||||
pathParam<Long>("sourceId"),
|
||||
queryParam<Int?>("pageNumber"),
|
||||
queryParam<String?>("sort"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Source Specific Manga Feed")
|
||||
description("Acquisition feed listing manga from a specific source. Supports pagination.")
|
||||
summary("OPDS Source Specific Series Feed (Explore)")
|
||||
description("Acquisition feed listing all series from a specific source.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, sourceId, pageNumber, lang ->
|
||||
behaviorOf = { ctx, sourceId, pageNumber, sort, lang ->
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getSourceFeed(sourceId, BASE_URL, pageNumber ?: 1, locale)
|
||||
OpdsFeedBuilder.getExploreSourceFeed(sourceId, BASE_URL, pageNumber ?: 1, sort ?: "popular", locale)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
@@ -308,27 +385,46 @@ object OpdsV1Controller {
|
||||
},
|
||||
)
|
||||
|
||||
// Category-Specific Manga Acquisition Feed
|
||||
/**
|
||||
* Builds an [OpdsMangaFilter] from the current request context, inheriting existing filters.
|
||||
*/
|
||||
private fun buildCriteriaFromContext(
|
||||
ctx: Context,
|
||||
initialCriteria: OpdsMangaFilter,
|
||||
): OpdsMangaFilter =
|
||||
initialCriteria.copy(
|
||||
sort = ctx.queryParam("sort"),
|
||||
filter = ctx.queryParam("filter"),
|
||||
)
|
||||
|
||||
/**
|
||||
* Serves an acquisition feed for series in the library from a specific source.
|
||||
*/
|
||||
val librarySourceFeed =
|
||||
handler(
|
||||
pathParam<Long>("sourceId"),
|
||||
documentWith = { withOperation { summary("OPDS Library Source Specific Series Feed") } },
|
||||
behaviorOf = { ctx, sourceId ->
|
||||
val criteria = buildCriteriaFromContext(ctx, OpdsMangaFilter(sourceId = sourceId, primaryFilter = PrimaryFilterType.SOURCE))
|
||||
getLibraryFeed(ctx, ctx.queryParam("pageNumber")?.toIntOrNull(), criteria)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
httpCode(HttpStatus.NOT_FOUND)
|
||||
},
|
||||
)
|
||||
|
||||
/**
|
||||
* Serves an acquisition feed for series in a specific category.
|
||||
*/
|
||||
val categoryFeed =
|
||||
handler(
|
||||
pathParam<Int>("categoryId"),
|
||||
queryParam<Int?>("pageNumber"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Category Specific Manga Feed")
|
||||
description("Acquisition feed listing manga belonging to a specific category. Supports pagination.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, categoryId, pageNumber, lang ->
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getCategoryFeed(categoryId, BASE_URL, pageNumber ?: 1, locale)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
}
|
||||
documentWith = { withOperation { summary("OPDS Category Specific Series Feed") } },
|
||||
behaviorOf = { ctx, categoryId ->
|
||||
val criteria =
|
||||
buildCriteriaFromContext(ctx, OpdsMangaFilter(categoryId = categoryId, primaryFilter = PrimaryFilterType.CATEGORY))
|
||||
getLibraryFeed(ctx, ctx.queryParam("pageNumber")?.toIntOrNull(), criteria)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
@@ -336,27 +432,16 @@ object OpdsV1Controller {
|
||||
},
|
||||
)
|
||||
|
||||
// Genre-Specific Manga Acquisition Feed
|
||||
/**
|
||||
* Serves an acquisition feed for series belonging to a specific genre.
|
||||
*/
|
||||
val genreFeed =
|
||||
handler(
|
||||
pathParam<String>("genre"),
|
||||
queryParam<Int?>("pageNumber"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Genre Specific Manga Feed")
|
||||
description("Acquisition feed listing manga belonging to a specific genre. Supports pagination.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, genre, pageNumber, lang ->
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getGenreFeed(genre, BASE_URL, pageNumber ?: 1, locale)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
}
|
||||
documentWith = { withOperation { summary("OPDS Genre Specific Series Feed") } },
|
||||
behaviorOf = { ctx, genre ->
|
||||
val criteria = buildCriteriaFromContext(ctx, OpdsMangaFilter(genre = genre, primaryFilter = PrimaryFilterType.GENRE))
|
||||
getLibraryFeed(ctx, ctx.queryParam("pageNumber")?.toIntOrNull(), criteria)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
@@ -364,27 +449,16 @@ object OpdsV1Controller {
|
||||
},
|
||||
)
|
||||
|
||||
// Status-Specific Manga Acquisition Feed
|
||||
/**
|
||||
* Serves an acquisition feed for series with a specific publication status.
|
||||
*/
|
||||
val statusMangaFeed =
|
||||
handler(
|
||||
pathParam<Long>("statusId"),
|
||||
queryParam<Int?>("pageNumber"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Status Specific Manga Feed")
|
||||
description("Acquisition feed listing manga with a specific publication status. Supports pagination.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, statusId, pageNumber, lang ->
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getStatusMangaFeed(statusId, BASE_URL, pageNumber ?: 1, locale)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
}
|
||||
pathParam<Int>("statusId"),
|
||||
documentWith = { withOperation { summary("OPDS Status Specific Series Feed") } },
|
||||
behaviorOf = { ctx, statusId ->
|
||||
val criteria = buildCriteriaFromContext(ctx, OpdsMangaFilter(statusId = statusId, primaryFilter = PrimaryFilterType.STATUS))
|
||||
getLibraryFeed(ctx, ctx.queryParam("pageNumber")?.toIntOrNull(), criteria)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
@@ -392,27 +466,22 @@ object OpdsV1Controller {
|
||||
},
|
||||
)
|
||||
|
||||
// Language-Specific Manga Acquisition Feed
|
||||
/**
|
||||
* Serves an acquisition feed for series of a specific content language.
|
||||
*/
|
||||
val languageFeed =
|
||||
handler(
|
||||
pathParam<String>("langCode"),
|
||||
queryParam<Int?>("pageNumber"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Content Language Specific Manga Feed")
|
||||
description("Acquisition feed listing manga of a specific content language. Supports pagination.")
|
||||
summary("OPDS Content Language Specific Series Feed")
|
||||
description("Acquisition feed listing series of a specific content language.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, contentLangCodePath, pageNumber, uiLangParam ->
|
||||
val uiLocale: Locale = LocalizationHelper.ctxToLocale(ctx, uiLangParam)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getLanguageFeed(contentLangCodePath, BASE_URL, pageNumber ?: 1, uiLocale)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
}
|
||||
behaviorOf = { ctx, langCode ->
|
||||
val criteria =
|
||||
buildCriteriaFromContext(ctx, OpdsMangaFilter(langCode = langCode, primaryFilter = PrimaryFilterType.LANGUAGE))
|
||||
getLibraryFeed(ctx, ctx.queryParam("pageNumber")?.toIntOrNull(), criteria)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
@@ -420,30 +489,27 @@ object OpdsV1Controller {
|
||||
},
|
||||
)
|
||||
|
||||
// --- Item-Specific Acquisition Feeds ---
|
||||
|
||||
// Manga Chapters Acquisition Feed
|
||||
val mangaFeed =
|
||||
/**
|
||||
* Serves an acquisition feed listing chapters for a specific series.
|
||||
*/
|
||||
val seriesChaptersFeed =
|
||||
handler(
|
||||
pathParam<Int>("mangaId"),
|
||||
pathParam<Int>("seriesId"),
|
||||
queryParam<Int?>("pageNumber"),
|
||||
queryParam<String?>("sort"),
|
||||
queryParam<String?>("filter"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Manga Chapters Feed")
|
||||
description(
|
||||
"Acquisition feed listing chapters for a specific manga. Supports pagination, sorting, and filtering. " +
|
||||
"Facets for sorting and filtering are provided.",
|
||||
)
|
||||
summary("OPDS Series Chapters Feed")
|
||||
description("Acquisition feed listing chapters for a specific series. Supports pagination, sorting, and filtering.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, mangaId, pageNumber, sort, filter, lang ->
|
||||
behaviorOf = { ctx, seriesId, pageNumber, sort, filter, lang ->
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getMangaFeed(mangaId, BASE_URL, pageNumber ?: 1, sort, filter, locale)
|
||||
OpdsFeedBuilder.getSeriesChaptersFeed(seriesId, BASE_URL, pageNumber ?: 1, sort, filter, locale)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
@@ -455,26 +521,25 @@ object OpdsV1Controller {
|
||||
},
|
||||
)
|
||||
|
||||
// Chapter Metadata Acquisition Feed
|
||||
/**
|
||||
* Serves an acquisition feed with detailed metadata for a single chapter.
|
||||
*/
|
||||
val chapterMetadataFeed =
|
||||
handler(
|
||||
pathParam<Int>("mangaId"),
|
||||
pathParam<Int>("seriesId"),
|
||||
pathParam<Int>("chapterIndex"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("OPDS Chapter Details Feed")
|
||||
description(
|
||||
"Acquisition feed providing detailed metadata for a specific chapter, " +
|
||||
"including download and streaming links if available.",
|
||||
)
|
||||
description("Acquisition feed providing detailed metadata for a specific chapter.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, mangaId, chapterIndex, lang ->
|
||||
behaviorOf = { ctx, seriesId, chapterIndex, lang ->
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getChapterMetadataFeed(mangaId, chapterIndex, BASE_URL, locale)
|
||||
OpdsFeedBuilder.getChapterMetadataFeed(seriesId, chapterIndex, BASE_URL, locale)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user