diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/OpdsGenerator.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/OpdsGenerator.kt index f71410184..8404aabd3 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/OpdsGenerator.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/OpdsGenerator.kt @@ -4,6 +4,7 @@ import org.gotson.komga.domain.persistence.MediaRepository import org.gotson.komga.domain.service.BookAnalyzer import org.gotson.komga.infrastructure.image.ImageConverter import org.gotson.komga.infrastructure.image.ImageType +import org.gotson.komga.interfaces.api.dto.MEDIATYPE_OPDS_AUTHENTICATION_JSON_VALUE import org.gotson.komga.interfaces.api.dto.MEDIATYPE_OPDS_JSON_VALUE import org.gotson.komga.interfaces.api.dto.MEDIATYPE_OPDS_PUBLICATION_JSON import org.gotson.komga.interfaces.api.dto.WPLinkDto @@ -39,6 +40,15 @@ class OpdsGenerator( ), ) + override fun getExtraLinkProperties(): Map> = + mapOf( + "authenticate" to + mapOf( + "href" to ServletUriComponentsBuilder.fromCurrentContextPath().pathSegment("opds", "v2").path(ROUTE_AUTH).toUriString(), + "type" to MEDIATYPE_OPDS_AUTHENTICATION_JSON_VALUE, + ), + ) + fun generateOpdsAuthDocument() = AuthenticationDocumentDto( id = ServletUriComponentsBuilder.fromCurrentContextPath().pathSegment("opds", "v2").path(ROUTE_AUTH).toUriString(), diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/WebPubGenerator.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/WebPubGenerator.kt index e01c21039..877a89171 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/WebPubGenerator.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/WebPubGenerator.kt @@ -54,13 +54,14 @@ class WebPubGenerator( ) } - protected open fun getDefaultMediaType(): MediaType = MEDIATYPE_WEBPUB_JSON + protected fun getDefaultMediaType(): MediaType = MEDIATYPE_WEBPUB_JSON protected fun buildThumbnailLinkDtos(bookId: String) = listOf( WPLinkDto( href = ServletUriComponentsBuilder.fromCurrentContextPath().pathSegment(*pathSegments.toTypedArray()).path("books/$bookId/thumbnail").toUriString(), type = thumbnailType.mediaType, + properties = getExtraLinkProperties(), ), ) @@ -204,7 +205,7 @@ class WebPubGenerator( ), ) - protected open fun getBookSeriesLink(bookDto: BookDto): List = emptyList() + protected fun getBookSeriesLink(bookDto: BookDto): List = emptyList() private fun WPMetadataDto.withSeriesMetadata(seriesMetadata: SeriesMetadata) = copy( @@ -236,16 +237,18 @@ class WebPubGenerator( ) } + protected fun getExtraLinkProperties(): Map> = emptyMap() + private fun BookDto.toWPLinkDtos(uriBuilder: UriComponentsBuilder): List { val komgaMediaType = KomgaMediaType.fromMediaType(media.mediaType) return buildList { // most appropriate manifest - add(WPLinkDto(rel = OpdsLinkRel.SELF, href = uriBuilder.cloneBuilder().path("books/$id/manifest").toUriString(), type = mediaProfileToWebPub(komgaMediaType?.profile))) + add(WPLinkDto(rel = OpdsLinkRel.SELF, href = uriBuilder.cloneBuilder().path("books/$id/manifest").toUriString(), type = mediaProfileToWebPub(komgaMediaType?.profile), properties = getExtraLinkProperties())) // PDF is also available under the Divina profile / EPUB that are Divina compatible if (komgaMediaType?.profile == MediaProfile.PDF || (komgaMediaType?.profile == MediaProfile.EPUB && media.epubDivinaCompatible)) - add(WPLinkDto(href = uriBuilder.cloneBuilder().path("books/$id/manifest/divina").toUriString(), type = MEDIATYPE_DIVINA_JSON_VALUE)) + add(WPLinkDto(href = uriBuilder.cloneBuilder().path("books/$id/manifest/divina").toUriString(), type = MEDIATYPE_DIVINA_JSON_VALUE, properties = getExtraLinkProperties())) // main acquisition link - add(WPLinkDto(rel = OpdsLinkRel.ACQUISITION, type = komgaMediaType?.exportType ?: media.mediaType, href = uriBuilder.cloneBuilder().path("books/$id/file").toUriString())) + add(WPLinkDto(rel = OpdsLinkRel.ACQUISITION, type = komgaMediaType?.exportType ?: media.mediaType, href = uriBuilder.cloneBuilder().path("books/$id/file").toUriString(), properties = getExtraLinkProperties())) } } diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/dto/WepPub.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/dto/WepPub.kt index 033c9cf5b..3d4530655 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/dto/WepPub.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/dto/WepPub.kt @@ -22,6 +22,7 @@ data class WPLinkDto( val height: Int? = null, val alternate: List = emptyList(), val children: List = emptyList(), + val properties: Map> = emptyMap(), ) @JsonInclude(JsonInclude.Include.NON_NULL)