mirror of
https://github.com/gotson/komga.git
synced 2026-05-09 05:10:19 +02:00
fix: book conversion could fail because of different path separators
This commit is contained in:
parent
5a0a21d953
commit
e577e4a78f
1 changed files with 19 additions and 6 deletions
|
|
@ -3,6 +3,7 @@ package org.gotson.komga.domain.service
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
|
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
|
||||||
|
import org.apache.commons.io.FilenameUtils
|
||||||
import org.apache.tika.mime.MediaType
|
import org.apache.tika.mime.MediaType
|
||||||
import org.gotson.komga.domain.model.Book
|
import org.gotson.komga.domain.model.Book
|
||||||
import org.gotson.komga.domain.model.BookConversionException
|
import org.gotson.komga.domain.model.BookConversionException
|
||||||
|
|
@ -86,14 +87,26 @@ class BookConverter(
|
||||||
|
|
||||||
val convertedMedia = bookAnalyzer.analyze(convertedBook)
|
val convertedMedia = bookAnalyzer.analyze(convertedBook)
|
||||||
|
|
||||||
if (convertedMedia.status != Media.Status.READY ||
|
try {
|
||||||
convertedMedia.mediaType != MediaType.APPLICATION_ZIP.toString() ||
|
when {
|
||||||
!convertedMedia.pages.containsAll(media.pages) ||
|
convertedMedia.status != Media.Status.READY
|
||||||
!convertedMedia.files.containsAll(media.files)
|
-> throw BookConversionException("Converted file could not be analyzed, aborting conversion")
|
||||||
) {
|
|
||||||
|
convertedMedia.mediaType != MediaType.APPLICATION_ZIP.toString()
|
||||||
|
-> throw BookConversionException("Converted file is not a zip file, aborting conversion")
|
||||||
|
|
||||||
|
!convertedMedia.pages.map { it.copy(fileName = FilenameUtils.getName(it.fileName)) }
|
||||||
|
.containsAll(media.pages.map { it.copy(fileName = FilenameUtils.getName(it.fileName)) })
|
||||||
|
-> throw BookConversionException("Converted file does not contain all pages from existing file, aborting conversion")
|
||||||
|
|
||||||
|
!convertedMedia.files.map { FilenameUtils.getName(it) }
|
||||||
|
.containsAll(media.files.map { FilenameUtils.getName(it) })
|
||||||
|
-> throw BookConversionException("Converted file does not contain all files from existing file, aborting conversion")
|
||||||
|
}
|
||||||
|
} catch (e: BookConversionException) {
|
||||||
destinationPath.deleteIfExists()
|
destinationPath.deleteIfExists()
|
||||||
exclude += book.id
|
exclude += book.id
|
||||||
throw BookConversionException("Converted file does not match existing file, aborting conversion")
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
if (book.path.deleteIfExists())
|
if (book.path.deleteIfExists())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue