Fix 500 error in OPDS (#2434)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
+9
-2
@@ -604,6 +604,13 @@ public class OpdsFeedService {
|
|||||||
return DateTimeFormatter.ISO_INSTANT.format(java.time.Instant.now());
|
return DateTimeFormatter.ISO_INSTANT.format(java.time.Instant.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasValidFilePath(Book book) {
|
||||||
|
return book.getFileName() != null
|
||||||
|
&& book.getLibraryPath() != null
|
||||||
|
&& book.getLibraryPath().getPath() != null
|
||||||
|
&& book.getFileSubPath() != null;
|
||||||
|
}
|
||||||
|
|
||||||
private String fileMimeType(Book book) {
|
private String fileMimeType(Book book) {
|
||||||
if (book == null || book.getBookType() == null) {
|
if (book == null || book.getBookType() == null) {
|
||||||
return "application/octet-stream";
|
return "application/octet-stream";
|
||||||
@@ -612,7 +619,7 @@ public class OpdsFeedService {
|
|||||||
case PDF -> "application/pdf";
|
case PDF -> "application/pdf";
|
||||||
case EPUB -> "application/epub+zip";
|
case EPUB -> "application/epub+zip";
|
||||||
case FB2 -> {
|
case FB2 -> {
|
||||||
if (book.getFileName() != null) {
|
if (hasValidFilePath(book)) {
|
||||||
ArchiveUtils.ArchiveType type = ArchiveUtils.detectArchiveType(new File(FileUtils.getBookFullPath(book)));
|
ArchiveUtils.ArchiveType type = ArchiveUtils.detectArchiveType(new File(FileUtils.getBookFullPath(book)));
|
||||||
if (type == ArchiveUtils.ArchiveType.ZIP) {
|
if (type == ArchiveUtils.ArchiveType.ZIP) {
|
||||||
yield "application/zip";
|
yield "application/zip";
|
||||||
@@ -632,7 +639,7 @@ public class OpdsFeedService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (book.getFileName() != null) {
|
if (hasValidFilePath(book)) {
|
||||||
ArchiveUtils.ArchiveType type = ArchiveUtils.detectArchiveType(new File(FileUtils.getBookFullPath(book)));
|
ArchiveUtils.ArchiveType type = ArchiveUtils.detectArchiveType(new File(FileUtils.getBookFullPath(book)));
|
||||||
yield switch (type) {
|
yield switch (type) {
|
||||||
case RAR -> "application/vnd.comicbook-rar";
|
case RAR -> "application/vnd.comicbook-rar";
|
||||||
|
|||||||
Reference in New Issue
Block a user