feat(OpdsFeedService): detect ZIP mime type for FB2 files when zipped (#2242)
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
+9
-1
@@ -607,7 +607,15 @@ public class OpdsFeedService {
|
||||
return switch (book.getBookType()) {
|
||||
case PDF -> "application/pdf";
|
||||
case EPUB -> "application/epub+zip";
|
||||
case FB2 -> "application/x-fictionbook+xml";
|
||||
case FB2 -> {
|
||||
if (book.getFileName() != null) {
|
||||
ArchiveUtils.ArchiveType type = ArchiveUtils.detectArchiveType(new File(FileUtils.getBookFullPath(book)));
|
||||
if (type == ArchiveUtils.ArchiveType.ZIP) {
|
||||
yield "application/zip";
|
||||
}
|
||||
}
|
||||
yield "application/x-fictionbook+xml";
|
||||
}
|
||||
case CBX -> {
|
||||
if (book.getArchiveType() != null) {
|
||||
yield switch (book.getArchiveType()) {
|
||||
|
||||
+16
@@ -135,6 +135,22 @@ class OpdsFeedServiceMimeTypeTest {
|
||||
assertThat(xml).contains("type=\"application/x-fictionbook+xml\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMimeTypeForZippedFb2() throws IOException {
|
||||
File zipAsFb2 = tempDir.resolve("book_zipped.fb2").toFile();
|
||||
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipAsFb2))) {
|
||||
zos.putNextEntry(new ZipEntry("book.fb2"));
|
||||
zos.write("<FictionBook>...</FictionBook>".getBytes());
|
||||
zos.closeEntry();
|
||||
}
|
||||
|
||||
Book book = createBook(BookFileType.FB2, "book_zipped.fb2");
|
||||
mockBooksPage(book);
|
||||
|
||||
String xml = opdsFeedService.generateCatalogFeed(request);
|
||||
assertThat(xml).contains("type=\"application/zip\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMimeTypeForZipNamedAsCbr() throws IOException {
|
||||
// Create a ZIP file named .cbr
|
||||
|
||||
Reference in New Issue
Block a user