fix(archive): infer archive type via Magic Numbers instead of filename (#79)

* chore(deps): bump actions/setup-node from 6.2.0 to 6.3.0 (#1)

Dependabot couldn't find the original pull request head commit, ea510f40fc1855aa17a782e05b0d30547e84955e.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump docker/setup-buildx-action from 3.12.0 to 4.0.0 (#2)

Dependabot couldn't find the original pull request head commit, faed6bf8a712c5fc793fa628157de25d97888131.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump docker/build-push-action from 6.19.2 to 7.0.0 (#3)

Dependabot couldn't find the original pull request head commit, f110823720b6dd773df014ba288a126d8837fe28.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump docker/login-action from 3.7.0 to 4.0.0 (#6)

Dependabot couldn't find the original pull request head commit, 9a8d7a1daf5afff06bb35e36607c3da9aa730e21.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix(archive): infer archive type via Magic Numbers instead of filename

* fix(archive): improve archive type detection and improve logging for cover image retrieval

---------

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
brios
2026-04-22 17:26:30 -04:00
committed by Zach Yale
co-authored by dependabot[bot]
parent dc1fa74af7
commit 3c0b5c0c9c
8 changed files with 48 additions and 73 deletions
@@ -93,30 +93,6 @@ class CbxConversionServiceTest {
.hasMessageContaining("No valid images found");
}
@Test
void isSupportedCbxFormat_WithSupportedFiles_ShouldReturnTrue() {
assertThat(cbxConversionService.isSupportedCbxFormat("test.cbz")).isTrue();
assertThat(cbxConversionService.isSupportedCbxFormat("test.CBZ")).isTrue();
assertThat(cbxConversionService.isSupportedCbxFormat("path/to/test.cbz")).isTrue();
assertThat(cbxConversionService.isSupportedCbxFormat("test.cbr")).isTrue();
assertThat(cbxConversionService.isSupportedCbxFormat("test.CBR")).isTrue();
assertThat(cbxConversionService.isSupportedCbxFormat("path/to/test.cbr")).isTrue();
assertThat(cbxConversionService.isSupportedCbxFormat("test.cb7")).isTrue();
assertThat(cbxConversionService.isSupportedCbxFormat("test.CB7")).isTrue();
assertThat(cbxConversionService.isSupportedCbxFormat("path/to/test.cb7")).isTrue();
}
@Test
void isSupportedCbxFormat_WithUnsupportedFormats_ShouldReturnFalse() {
assertThat(cbxConversionService.isSupportedCbxFormat("test.zip")).isFalse();
assertThat(cbxConversionService.isSupportedCbxFormat("test.pdf")).isFalse();
assertThat(cbxConversionService.isSupportedCbxFormat("test.epub")).isFalse();
assertThat(cbxConversionService.isSupportedCbxFormat("test.txt")).isFalse();
assertThat(cbxConversionService.isSupportedCbxFormat("test")).isFalse();
assertThat(cbxConversionService.isSupportedCbxFormat(null)).isFalse();
assertThat(cbxConversionService.isSupportedCbxFormat("")).isFalse();
}
@Test
void convertCbxToEpub_WithNullBookEntity_ShouldUseDefaultMetadata() throws IOException, TemplateException, RarException {
File epubFile = cbxConversionService.convertCbxToEpub(testCbzFile, tempDir.toFile(), null,85);
@@ -105,7 +105,12 @@ class OpdsFeedServiceMimeTypeTest {
}
@Test
void testMimeTypeForCbr() {
void testMimeTypeForCbr() throws IOException {
File rarFile = tempDir.resolve("comic.cbr").toFile();
try (FileOutputStream fos = new FileOutputStream(rarFile)) {
// RAR 4.x magic bytes
fos.write(new byte[]{0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00});
}
Book book = createBook(BookFileType.CBX, "comic.cbr");
mockBooksPage(book);
String xml = opdsFeedService.generateCatalogFeed(request);
@@ -113,7 +118,12 @@ class OpdsFeedServiceMimeTypeTest {
}
@Test
void testMimeTypeForCb7() {
void testMimeTypeForCb7() throws IOException {
File sevenZFile = tempDir.resolve("comic.cb7").toFile();
try (FileOutputStream fos = new FileOutputStream(sevenZFile)) {
// 7z magic bytes
fos.write(new byte[]{0x37, 0x7A, (byte) 0xBC, (byte) 0xAF, 0x27, 0x1C});
}
Book book = createBook(BookFileType.CBX, "comic.cb7");
mockBooksPage(book);
String xml = opdsFeedService.generateCatalogFeed(request);
@@ -122,10 +132,12 @@ class OpdsFeedServiceMimeTypeTest {
@Test
void testMimeTypeForCbt() {
// CBT is TAR-based; ArchiveUtils has no TAR magic byte detection,
// so an unrecognised archive defaults to the CBX fallback mime type.
Book book = createBook(BookFileType.CBX, "comic.cbt");
mockBooksPage(book);
String xml = opdsFeedService.generateCatalogFeed(request);
assertThat(xml).contains("type=\"application/x-tar\"");
assertThat(xml).contains("type=\"application/vnd.comicbook+zip\"");
}
@Test
@@ -495,10 +495,11 @@ class OpdsFeedServiceTest {
var method = OpdsFeedService.class.getDeclaredMethod("fileMimeType", BookFile.class);
method.setAccessible(true);
// The reliable path: archive type is cached during indexing
BookFile bookFile = BookFile.builder()
.bookType(BookFileType.CBX)
.fileName("comic.cbr")
.archiveType(ArchiveUtils.ArchiveType.UNKNOWN)
.archiveType(ArchiveUtils.ArchiveType.RAR)
.build();
String mimeType = (String) method.invoke(opdsFeedService, bookFile);