From 7e5a1412ca1a0278f2f5169fa55d5e25fbb75480 Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Sat, 27 Jun 2020 10:40:37 +0800 Subject: [PATCH] fix(opds): prepend position for series in ordered collection --- .../gotson/komga/interfaces/opds/OpdsController.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/opds/OpdsController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/opds/OpdsController.kt index b145f3703..7cf708479 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/opds/OpdsController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/opds/OpdsController.kt @@ -319,7 +319,9 @@ class OpdsController( if (!collection.ordered) series.sortedBy { it.metadata.titleSort } else series - val entries = sorted.map { it.toOpdsEntry() } + val entries = sorted.mapIndexed { index, it -> + it.toOpdsEntry(if (collection.ordered) index + 1 else null) + } OpdsFeedNavigation( id = collection.id.toString(), @@ -336,14 +338,16 @@ class OpdsController( } - private fun SeriesWithInfo.toOpdsEntry(): OpdsEntryNavigation = - OpdsEntryNavigation( - title = metadata.title, + private fun SeriesWithInfo.toOpdsEntry(prepend: Int? = null): OpdsEntryNavigation { + val pre = prepend?.let { decimalFormat.format(it) + " - " } ?: "" + return OpdsEntryNavigation( + title = pre + metadata.title, updated = series.lastModifiedDate.atZone(ZoneId.systemDefault()) ?: ZonedDateTime.now(), id = series.id.toString(), content = "", link = OpdsLinkFeedNavigation(OpdsLinkRel.SUBSECTION, "${routeBase}series/${series.id}") ) + } private fun BookWithInfo.toOpdsEntry(prependNumber: Boolean): OpdsEntryAcquisition { val mediaTypes = media.pages.map { it.mediaType }.distinct()