mirror of
https://github.com/gotson/komga.git
synced 2026-05-01 11:25:24 +02:00
fix(komga): empty generated thumbnails would be saved in DB
Closes: #1338
This commit is contained in:
parent
77b8a328eb
commit
15920b710e
4 changed files with 18 additions and 11 deletions
|
|
@ -0,0 +1,4 @@
|
|||
delete
|
||||
from THUMBNAIL_BOOK
|
||||
where TYPE = 'GENERATED'
|
||||
and THUMBNAIL is null;
|
||||
|
|
@ -15,6 +15,7 @@ open class CodedException : Exception {
|
|||
fun Exception.withCode(code: String) = CodedException(this, code)
|
||||
|
||||
class MediaNotReadyException : Exception()
|
||||
class NoThumbnailFoundException : Exception()
|
||||
class MediaUnsupportedException(message: String, code: String = "") : CodedException(message, code)
|
||||
class ImageConversionException(message: String, code: String = "") : CodedException(message, code)
|
||||
class DirectoryNotFoundException(message: String, code: String = "") : CodedException(message, code)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import org.gotson.komga.domain.model.MediaNotReadyException
|
|||
import org.gotson.komga.domain.model.MediaProfile
|
||||
import org.gotson.komga.domain.model.MediaType
|
||||
import org.gotson.komga.domain.model.MediaUnsupportedException
|
||||
import org.gotson.komga.domain.model.NoThumbnailFoundException
|
||||
import org.gotson.komga.domain.model.ThumbnailBook
|
||||
import org.gotson.komga.domain.model.TypedBytes
|
||||
import org.gotson.komga.infrastructure.configuration.KomgaSettingsProvider
|
||||
|
|
@ -143,7 +144,10 @@ class BookAnalyzer(
|
|||
return Media(status = Media.Status.READY, pages = pages)
|
||||
}
|
||||
|
||||
@Throws(MediaNotReadyException::class)
|
||||
@Throws(
|
||||
MediaNotReadyException::class,
|
||||
NoThumbnailFoundException::class,
|
||||
)
|
||||
fun generateThumbnail(book: BookWithMedia): ThumbnailBook {
|
||||
logger.info { "Generate thumbnail for book: $book" }
|
||||
|
||||
|
|
@ -152,22 +156,17 @@ class BookAnalyzer(
|
|||
throw MediaNotReadyException()
|
||||
}
|
||||
|
||||
val thumbnail = try {
|
||||
getPoster(book)?.let { cover ->
|
||||
imageConverter.resizeImageToByteArray(cover.bytes, thumbnailType, komgaSettingsProvider.thumbnailSize.maxEdge)
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
logger.warn(ex) { "Could not generate thumbnail for book: $book" }
|
||||
null
|
||||
}
|
||||
val thumbnail = getPoster(book)?.let { cover ->
|
||||
imageConverter.resizeImageToByteArray(cover.bytes, thumbnailType, komgaSettingsProvider.thumbnailSize.maxEdge)
|
||||
} ?: throw NoThumbnailFoundException()
|
||||
|
||||
return ThumbnailBook(
|
||||
thumbnail = thumbnail,
|
||||
type = ThumbnailBook.Type.GENERATED,
|
||||
bookId = book.book.id,
|
||||
mediaType = thumbnailType.mediaType,
|
||||
dimension = thumbnail?.let { imageAnalyzer.getDimension(it.inputStream()) } ?: Dimension(0, 0),
|
||||
fileSize = thumbnail?.size?.toLong() ?: 0,
|
||||
dimension = imageAnalyzer.getDimension(thumbnail.inputStream()) ?: Dimension(0, 0),
|
||||
fileSize = thumbnail.size.toLong(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import org.gotson.komga.domain.model.Media
|
|||
import org.gotson.komga.domain.model.MediaExtensionEpub
|
||||
import org.gotson.komga.domain.model.MediaNotReadyException
|
||||
import org.gotson.komga.domain.model.MediaProfile
|
||||
import org.gotson.komga.domain.model.NoThumbnailFoundException
|
||||
import org.gotson.komga.domain.model.R2Progression
|
||||
import org.gotson.komga.domain.model.ReadProgress
|
||||
import org.gotson.komga.domain.model.ThumbnailBook
|
||||
|
|
@ -121,6 +122,8 @@ class BookLifecycle(
|
|||
logger.info { "Generate thumbnail and persist for book: $book" }
|
||||
try {
|
||||
addThumbnailForBook(bookAnalyzer.generateThumbnail(BookWithMedia(book, mediaRepository.findById(book.id))), MarkSelectedPreference.IF_NONE_OR_GENERATED)
|
||||
} catch (ex: NoThumbnailFoundException) {
|
||||
logger.error { "Error while creating thumbnail" }
|
||||
} catch (ex: Exception) {
|
||||
logger.error(ex) { "Error while creating thumbnail" }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue