fix(opds): add audiobook covers for opds navigation (#1425)
This commit is contained in:
@@ -67,6 +67,16 @@ public class OpdsController {
|
||||
public ResponseEntity<Resource> getBookCover(@Parameter(description = "ID of the book") @PathVariable long bookId) {
|
||||
opdsBookService.validateBookContentAccess(bookId, getOpdsUserId());
|
||||
Resource coverImage = bookService.getBookThumbnail(bookId);
|
||||
|
||||
if (coverImage == null) {
|
||||
// Fall back to audiobook if possible
|
||||
coverImage = bookService.getAudiobookCover(bookId);
|
||||
}
|
||||
|
||||
if (coverImage == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
String contentType = "image/jpeg";
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType(contentType))
|
||||
|
||||
@@ -555,6 +555,20 @@ public class OpdsFeedService {
|
||||
}
|
||||
}
|
||||
|
||||
private Instant getCoverUpdatedOn(Book book) {
|
||||
if (book.getMetadata() != null) {
|
||||
if (book.getMetadata().getCoverUpdatedOn() != null) {
|
||||
return book.getMetadata().getCoverUpdatedOn();
|
||||
}
|
||||
|
||||
if (book.getMetadata().getAudiobookCoverUpdatedOn() != null) {
|
||||
return book.getMetadata().getAudiobookCoverUpdatedOn();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void appendLinks(StringBuilder feed, Book book) {
|
||||
// Add acquisition link for primary file
|
||||
if (book.getPrimaryFile() != null) {
|
||||
@@ -568,8 +582,9 @@ public class OpdsFeedService {
|
||||
}
|
||||
}
|
||||
|
||||
if (book.getMetadata() != null && book.getMetadata().getCoverUpdatedOn() != null) {
|
||||
String coverUrl = "/api/v1/opds/" + book.getId() + "/cover?" + book.getMetadata().getCoverUpdatedOn();
|
||||
Instant coverUpdatedOn = getCoverUpdatedOn(book);
|
||||
if (coverUpdatedOn != null) {
|
||||
String coverUrl = "/api/v1/opds/" + book.getId() + "/cover?" + coverUpdatedOn;
|
||||
feed.append(" <link rel=\"http://opds-spec.org/image\" href=\"")
|
||||
.append(escapeXml(coverUrl)).append("\" type=\"image/jpeg\"/>\n");
|
||||
feed.append(" <link rel=\"http://opds-spec.org/image/thumbnail\" href=\"")
|
||||
|
||||
Reference in New Issue
Block a user