Skip to content

Commit e03cca1

Browse files
authored
Fix 500 error in OPDS (#2434)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
1 parent 21076d4 commit e03cca1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

booklore-api/src/main/java/com/adityachandel/booklore/service/opds/OpdsFeedService.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,13 @@ private String now() {
604604
return DateTimeFormatter.ISO_INSTANT.format(java.time.Instant.now());
605605
}
606606

607+
private boolean hasValidFilePath(Book book) {
608+
return book.getFileName() != null
609+
&& book.getLibraryPath() != null
610+
&& book.getLibraryPath().getPath() != null
611+
&& book.getFileSubPath() != null;
612+
}
613+
607614
private String fileMimeType(Book book) {
608615
if (book == null || book.getBookType() == null) {
609616
return "application/octet-stream";
@@ -612,7 +619,7 @@ private String fileMimeType(Book book) {
612619
case PDF -> "application/pdf";
613620
case EPUB -> "application/epub+zip";
614621
case FB2 -> {
615-
if (book.getFileName() != null) {
622+
if (hasValidFilePath(book)) {
616623
ArchiveUtils.ArchiveType type = ArchiveUtils.detectArchiveType(new File(FileUtils.getBookFullPath(book)));
617624
if (type == ArchiveUtils.ArchiveType.ZIP) {
618625
yield "application/zip";
@@ -632,7 +639,7 @@ yield switch (book.getArchiveType()) {
632639
};
633640
}
634641

635-
if (book.getFileName() != null) {
642+
if (hasValidFilePath(book)) {
636643
ArchiveUtils.ArchiveType type = ArchiveUtils.detectArchiveType(new File(FileUtils.getBookFullPath(book)));
637644
yield switch (type) {
638645
case RAR -> "application/vnd.comicbook-rar";

0 commit comments

Comments
 (0)