mirror of
https://github.com/gotson/komga.git
synced 2025-01-08 11:47:47 +08:00
fix(komga): mark broken EPUB files as ERROR instead of falling back to CBZ
This commit is contained in:
parent
a3439dd6af
commit
acf080be9d
@ -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 |
|
||||
|
@ -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",
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
|
BIN
komga/src/test/resources/archives/zip-as-epub.epub
Normal file
BIN
komga/src/test/resources/archives/zip-as-epub.epub
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user