From 871a92a7835333ea11014ac06ead5b434a44c23d Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Sat, 21 Mar 2020 11:15:29 +0800 Subject: [PATCH] fix(api): use etag on book thumbnails closes #117 --- .../org/gotson/komga/interfaces/rest/BookController.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/BookController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/BookController.kt index 0dc97a024..71fc19fca 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/BookController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/BookController.kt @@ -179,22 +179,25 @@ class BookController( @GetMapping(value = [ "api/v1/books/{bookId}/thumbnail", "opds/v1.2/books/{bookId}/thumbnail" - ], produces = [MediaType.IMAGE_PNG_VALUE]) + ], produces = [MediaType.IMAGE_JPEG_VALUE]) fun getBookThumbnail( @AuthenticationPrincipal principal: KomgaPrincipal, request: WebRequest, @PathVariable bookId: Long ): ResponseEntity = bookRepository.findByIdOrNull(bookId)?.let { book -> - if (request.checkNotModified(getBookLastModified(book))) { + val etag = book.id.toString() + if (request.checkNotModified(etag, getBookLastModified(book))) { return@let ResponseEntity .status(HttpStatus.NOT_MODIFIED) + .eTag(etag) .setNotModified(book) .body(ByteArray(0)) } if (!principal.user.canAccessBook(book)) throw ResponseStatusException(HttpStatus.UNAUTHORIZED) if (book.media.thumbnail != null) { ResponseEntity.ok() + .eTag(etag) .setNotModified(book) .body(book.media.thumbnail) } else throw ResponseStatusException(HttpStatus.NOT_FOUND)