fix(komga): mark broken EPUB files as ERROR instead of falling back to CBZ

This commit is contained in:
Gauthier Roebroeck 2023-11-30 10:41:30 +08:00
parent a3439dd6af
commit acf080be9d
5 changed files with 21 additions and 1 deletions

View File

@ -35,3 +35,4 @@
| ERR_1029 | ComicRack CBL does not contain any Book element |
| ERR_1030 | ComicRack CBL has no Name element |
| ERR_1031 | ComicRack CBL Book is missing series or number |
| ERR_1032 | EPUB file has wrong media type |

View File

@ -750,7 +750,8 @@
"ERR_1028": "OpenID Connect login error: no email attribute",
"ERR_1029": "ComicRack CBL does not contain any Book element",
"ERR_1030": "ComicRack CBL has no Name element",
"ERR_1031": "ComicRack CBL Book is missing series or number"
"ERR_1031": "ComicRack CBL Book is missing series or number",
"ERR_1032": "EPUB file has wrong media type"
},
"filter": {
"age_rating": "age rating",

View File

@ -30,6 +30,7 @@ import java.io.ByteArrayOutputStream
import java.nio.file.AccessDeniedException
import java.nio.file.NoSuchFileException
import javax.imageio.ImageIO
import kotlin.io.path.extension
private val logger = KotlinLogging.logger {}
@ -62,6 +63,11 @@ class BookAnalyzer(
MediaType.fromMediaType(it) ?: return Media(mediaType = it, status = Media.Status.UNSUPPORTED, comment = "ERR_1001", bookId = book.id)
}
if (book.path.extension.lowercase() == "epub" && mediaType != MediaType.EPUB) {
logger.warn { "Epub file detected as zip, file is probably broken: ${book.path}" }
return Media(mediaType = mediaType.type, status = Media.Status.ERROR, comment = "ERR_1032", bookId = book.id)
}
when (mediaType.profile) {
MediaProfile.DIVINA -> analyzeDivina(book, mediaType, analyzeDimensions)
MediaProfile.PDF -> analyzePdf(book, analyzeDimensions)

View File

@ -133,6 +133,18 @@ class BookAnalyzerTest(
assertThat(media.pages).hasSize(0)
}
@Test
fun `given broken epub archive when analyzing then media status is ERROR`() {
val file = ClassPathResource("archives/zip-as-epub.epub")
val book = Book("book", file.url, LocalDateTime.now())
val media = bookAnalyzer.analyze(book, false)
assertThat(media.mediaType).isEqualTo("application/zip")
assertThat(media.status).isEqualTo(Media.Status.ERROR)
assertThat(media.pages).hasSize(0)
}
@Test
fun `given book with a single page when hashing then all pages are hashed`() {
val book = makeBook("book1")

Binary file not shown.