Skip to content

Commit

Permalink
refactor(webpub): cleanup webpub manifest acquisition links
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Sep 8, 2023
1 parent e50591f commit 32ef331
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,14 @@ private fun WPMetadataDto.withAuthors(authors: List<AuthorDto>): WPMetadataDto {

private fun BookDto.toWPLinkDtos(uriBuilder: UriComponentsBuilder): List<WPLinkDto> {
val komgaMediaType = KomgaMediaType.fromMediaType(media.mediaType)
val download = WPLinkDto(rel = OpdsLinkRel.ACQUISITION, type = media.mediaType, href = uriBuilder.cloneBuilder().path("books/$id/file").toUriString())

return listOfNotNull(
// most appropriate manifest
WPLinkDto(rel = OpdsLinkRel.SELF, href = uriBuilder.cloneBuilder().path("books/$id/manifest").toUriString(), type = mediaTypeToWebPub(komgaMediaType)),
// PDF is also available under the Divina profile
if (komgaMediaType == PDF) WPLinkDto(href = uriBuilder.cloneBuilder().path("books/$id/manifest/divina").toUriString(), type = MEDIATYPE_DIVINA_JSON_VALUE) else null,
// main acquisition link
download,
// extra acquisition link with a different export type, useful for CBR/CBZ
komgaMediaType?.let { download.copy(type = it.exportType) },
).distinct()
WPLinkDto(rel = OpdsLinkRel.ACQUISITION, type = komgaMediaType?.exportType ?: media.mediaType, href = uriBuilder.cloneBuilder().path("books/$id/file").toUriString()),
)
}

private fun mediaTypeToWebPub(mediaType: KMediaType?): String = when (mediaType) {
Expand Down

0 comments on commit 32ef331

Please sign in to comment.