fix(api): disable content negotiation for images in webpub manifest

This commit is contained in:
Gauthier Roebroeck 2024-03-15 14:18:09 +08:00
parent ec3eb440be
commit 5a94ee1c4a
2 changed files with 5 additions and 3 deletions

View file

@ -78,7 +78,7 @@ class WebPubGenerator(
readingOrder =
pages.mapIndexed { index: Int, page: BookPage ->
WPLinkDto(
href = uriBuilder.cloneBuilder().path("books/${bookDto.id}/pages/${index + 1}").toUriString(),
href = uriBuilder.cloneBuilder().path("books/${bookDto.id}/pages/${index + 1}").queryParam("contentNegotiation", "false").toUriString(),
type = page.mediaType,
width = page.dimension?.width,
height = page.dimension?.height,
@ -86,7 +86,7 @@ class WebPubGenerator(
if (!recommendedImageMediaTypes.contains(page.mediaType) && imageConverter.canConvertMediaType(page.mediaType, MediaType.IMAGE_JPEG_VALUE))
listOf(
WPLinkDto(
href = uriBuilder.cloneBuilder().path("books/${bookDto.id}/pages/${index + 1}").queryParam("convert", "jpeg").toUriString(),
href = uriBuilder.cloneBuilder().path("books/${bookDto.id}/pages/${index + 1}").queryParam("contentNegotiation", "false").queryParam("convert", "jpeg").toUriString(),
type = MediaType.IMAGE_JPEG_VALUE,
width = page.dimension?.width,
height = page.dimension?.height,

View file

@ -436,8 +436,10 @@ class BookController(
@Parameter(description = "Some very limited server driven content negotiation is handled. If a book is a PDF book, and the Accept header contains 'application/pdf' as a more specific type than other 'image/' types, a raw PDF page will be returned.")
@RequestHeader(HttpHeaders.ACCEPT, required = false)
acceptHeaders: MutableList<MediaType>?,
@RequestParam(value = "contentNegotiation", defaultValue = "true")
contentNegotiation: Boolean,
): ResponseEntity<ByteArray> =
commonBookController.getBookPageInternal(bookId, if (zeroBasedIndex) pageNumber + 1 else pageNumber, convertTo, request, principal, acceptHeaders)
commonBookController.getBookPageInternal(bookId, if (zeroBasedIndex) pageNumber + 1 else pageNumber, convertTo, request, principal, if (contentNegotiation) acceptHeaders else null)
@ApiResponse(content = [Content(schema = Schema(type = "string", format = "binary"))])
@GetMapping(