mirror of
https://github.com/gotson/komga.git
synced 2026-05-09 05:10:19 +02:00
feat(opds): add authenticate property for Aldiko/Cantook
This commit is contained in:
parent
77bad31064
commit
aaf958d53b
3 changed files with 19 additions and 5 deletions
|
|
@ -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<String, Map<String, Any>> =
|
||||
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(),
|
||||
|
|
|
|||
|
|
@ -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<WPLinkDto> = emptyList()
|
||||
protected fun getBookSeriesLink(bookDto: BookDto): List<WPLinkDto> = emptyList()
|
||||
|
||||
private fun WPMetadataDto.withSeriesMetadata(seriesMetadata: SeriesMetadata) =
|
||||
copy(
|
||||
|
|
@ -236,16 +237,18 @@ class WebPubGenerator(
|
|||
)
|
||||
}
|
||||
|
||||
protected fun getExtraLinkProperties(): Map<String, Map<String, Any>> = emptyMap()
|
||||
|
||||
private fun BookDto.toWPLinkDtos(uriBuilder: UriComponentsBuilder): List<WPLinkDto> {
|
||||
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()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ data class WPLinkDto(
|
|||
val height: Int? = null,
|
||||
val alternate: List<WPLinkDto> = emptyList(),
|
||||
val children: List<WPLinkDto> = emptyList(),
|
||||
val properties: Map<String, Map<String, Any>> = emptyMap(),
|
||||
)
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
|
|
|
|||
Loading…
Reference in a new issue