mirror of
https://github.com/gotson/komga.git
synced 2026-05-09 05:10:19 +02:00
refactor(komga): make Media.pageCount explicit
This commit is contained in:
parent
82e58870b8
commit
21e3e7a269
11 changed files with 24 additions and 15 deletions
|
|
@ -6,6 +6,7 @@ data class Media(
|
|||
val status: Status = Status.UNKNOWN,
|
||||
val mediaType: String? = null,
|
||||
val pages: List<BookPage> = emptyList(),
|
||||
val pageCount: Int = pages.size,
|
||||
val files: List<String> = emptyList(),
|
||||
val comment: String? = null,
|
||||
val bookId: String = "",
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class BookAnalyzer(
|
|||
|
||||
val files = others.map { it.name }
|
||||
|
||||
return Media(mediaType = mediaType, status = Media.Status.READY, pages = pages, files = files, comment = entriesErrorSummary, bookId = book.id)
|
||||
return Media(mediaType = mediaType, status = Media.Status.READY, pages = pages, pageCount = pages.size, files = files, comment = entriesErrorSummary, bookId = book.id)
|
||||
} catch (ade: AccessDeniedException) {
|
||||
logger.error(ade) { "Error while analyzing book: $book" }
|
||||
return Media(status = Media.Status.ERROR, comment = "ERR_1000", bookId = book.id)
|
||||
|
|
@ -150,8 +150,8 @@ class BookAnalyzer(
|
|||
throw MediaNotReadyException()
|
||||
}
|
||||
|
||||
if (number > book.media.pages.size || number <= 0) {
|
||||
logger.error { "Page number #$number is out of bounds. Book has ${book.media.pages.size} pages" }
|
||||
if (number > book.media.pageCount || number <= 0) {
|
||||
logger.error { "Page number #$number is out of bounds. Book has ${book.media.pageCount} pages" }
|
||||
throw IndexOutOfBoundsException("Page $number does not exist")
|
||||
}
|
||||
|
||||
|
|
@ -170,8 +170,8 @@ class BookAnalyzer(
|
|||
throw MediaNotReadyException()
|
||||
}
|
||||
|
||||
if (number > book.media.pages.size || number <= 0) {
|
||||
logger.error { "Page number #$number is out of bounds. Book has ${book.media.pages.size} pages" }
|
||||
if (number > book.media.pageCount || number <= 0) {
|
||||
logger.error { "Page number #$number is out of bounds. Book has ${book.media.pageCount} pages" }
|
||||
throw IndexOutOfBoundsException("Page $number does not exist")
|
||||
}
|
||||
|
||||
|
|
@ -203,7 +203,7 @@ class BookAnalyzer(
|
|||
*/
|
||||
fun hashPages(book: BookWithMedia): Media {
|
||||
val hashedPages = book.media.pages.mapIndexed { index, bookPage ->
|
||||
if (bookPage.fileHash.isBlank() && (index < pageHashing || index >= (book.media.pages.size - pageHashing))) {
|
||||
if (bookPage.fileHash.isBlank() && (index < pageHashing || index >= (book.media.pageCount - pageHashing))) {
|
||||
val content = getPageContent(book, index + 1)
|
||||
val hash = hashPage(bookPage, content)
|
||||
bookPage.copy(fileHash = hash)
|
||||
|
|
|
|||
|
|
@ -69,9 +69,9 @@ class BookLifecycle(
|
|||
transactionTemplate.executeWithoutResult {
|
||||
// if the number of pages has changed, delete all read progress for that book
|
||||
mediaRepository.findById(book.id).let { previous ->
|
||||
if (previous.status == Media.Status.OUTDATED && previous.pages.size != media.pages.size) {
|
||||
if (previous.status == Media.Status.OUTDATED && previous.pageCount != media.pageCount) {
|
||||
val adjustedProgress = readProgressRepository.findAllByBookId(book.id)
|
||||
.map { it.copy(page = if (it.completed) media.pages.size else 1) }
|
||||
.map { it.copy(page = if (it.completed) media.pageCount else 1) }
|
||||
if (adjustedProgress.isNotEmpty()) {
|
||||
logger.info { "Number of pages differ, adjust read progress for book" }
|
||||
readProgressRepository.save(adjustedProgress)
|
||||
|
|
@ -345,7 +345,7 @@ class BookLifecycle(
|
|||
fun markReadProgressCompleted(bookId: String, user: KomgaUser) {
|
||||
val media = mediaRepository.findById(bookId)
|
||||
|
||||
val progress = ReadProgress(bookId, user.id, media.pages.size, true)
|
||||
val progress = ReadProgress(bookId, user.id, media.pageCount, true)
|
||||
readProgressRepository.save(progress)
|
||||
eventPublisher.publishEvent(DomainEvent.ReadProgressChanged(progress))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ class MediaDao(
|
|||
it.status,
|
||||
it.mediaType,
|
||||
it.comment,
|
||||
it.pages.size,
|
||||
it.pageCount,
|
||||
)
|
||||
}
|
||||
}.execute()
|
||||
|
|
@ -189,7 +189,7 @@ class MediaDao(
|
|||
.set(m.STATUS, media.status.toString())
|
||||
.set(m.MEDIA_TYPE, media.mediaType)
|
||||
.set(m.COMMENT, media.comment)
|
||||
.set(m.PAGE_COUNT, media.pages.size)
|
||||
.set(m.PAGE_COUNT, media.pageCount)
|
||||
.set(m.LAST_MODIFIED_DATE, LocalDateTime.now(ZoneId.of("Z")))
|
||||
.where(m.BOOK_ID.eq(media.bookId))
|
||||
.execute()
|
||||
|
|
@ -229,6 +229,7 @@ class MediaDao(
|
|||
status = Media.Status.valueOf(status),
|
||||
mediaType = mediaType,
|
||||
pages = pages,
|
||||
pageCount = pageCount,
|
||||
files = files,
|
||||
comment = comment,
|
||||
bookId = bookId,
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class IsbnBarcodeProvider(
|
|||
setOf(BookMetadataPatchCapability.ISBN)
|
||||
|
||||
override fun getBookMetadataFromBook(book: BookWithMedia): BookMetadataPatch? {
|
||||
val pagesToTry = (1..book.media.pages.size).toList().let {
|
||||
val pagesToTry = (1..book.media.pageCount).toList().let {
|
||||
(it.takeLast(PAGES_LAST).reversed() + it.take(PAGES_FIRST)).distinct()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ fun BookDto.toManifestPdf(media: Media, seriesMetadata: SeriesMetadata): WPPubli
|
|||
metadata = it.metadata
|
||||
.withSeriesMetadata(seriesMetadata)
|
||||
.copy(conformsTo = PROFILE_PDF),
|
||||
readingOrder = List(media.pages.size) { index: Int ->
|
||||
readingOrder = List(media.pageCount) { index: Int ->
|
||||
WPLinkDto(
|
||||
href = uriBuilder.cloneBuilder().path("books/$id/pages/${index + 1}/raw").toUriString(),
|
||||
type = PDF.type,
|
||||
|
|
|
|||
|
|
@ -684,9 +684,9 @@ class OpdsController(
|
|||
val mediaTypes = media.pages.map { it.mediaType }.distinct()
|
||||
|
||||
val opdsLinkPageStreaming = if (mediaTypes.size == 1 && mediaTypes.first() in opdsPseSupportedFormats) {
|
||||
OpdsLinkPageStreaming(mediaTypes.first(), uriBuilder("books/$id/pages/").toUriString() + "{pageNumber}", media.pages.size, readProgress?.page, readProgress?.readDate)
|
||||
OpdsLinkPageStreaming(mediaTypes.first(), uriBuilder("books/$id/pages/").toUriString() + "{pageNumber}", media.pageCount, readProgress?.page, readProgress?.readDate)
|
||||
} else {
|
||||
OpdsLinkPageStreaming("image/jpeg", uriBuilder("books/$id/pages/").toUriString() + "{pageNumber}?convert=jpeg", media.pages.size, readProgress?.page, readProgress?.readDate)
|
||||
OpdsLinkPageStreaming("image/jpeg", uriBuilder("books/$id/pages/").toUriString() + "{pageNumber}?convert=jpeg", media.pageCount, readProgress?.page, readProgress?.readDate)
|
||||
}
|
||||
|
||||
return OpdsEntryAcquisition(
|
||||
|
|
|
|||
|
|
@ -448,6 +448,7 @@ class BookImporterTest(
|
|||
media.copy(
|
||||
status = Media.Status.READY,
|
||||
pages = (1..10).map { BookPage("$it", "image/jpeg") },
|
||||
pageCount = 10,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ class BookLifecycleTest(
|
|||
media.copy(
|
||||
status = Media.Status.OUTDATED,
|
||||
pages = (1..10).map { BookPage("$it", "image/jpeg") },
|
||||
pageCount = 10,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -130,6 +131,7 @@ class BookLifecycleTest(
|
|||
media.copy(
|
||||
status = Media.Status.OUTDATED,
|
||||
pages = (1..10).map { BookPage("$it", "image/jpeg") },
|
||||
pageCount = 10,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1195,6 +1195,7 @@ class BookControllerTest(
|
|||
media.copy(
|
||||
status = Media.Status.READY,
|
||||
pages = (1..10).map { BookPage("$it", "image/jpeg") },
|
||||
pageCount = 10,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -1237,6 +1238,7 @@ class BookControllerTest(
|
|||
media.copy(
|
||||
status = Media.Status.READY,
|
||||
pages = (1..10).map { BookPage("$it", "image/jpeg") },
|
||||
pageCount = 10,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -1279,6 +1281,7 @@ class BookControllerTest(
|
|||
media.copy(
|
||||
status = Media.Status.READY,
|
||||
pages = (1..10).map { BookPage("$it", "image/jpeg") },
|
||||
pageCount = 10,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1067,6 +1067,7 @@ class SeriesControllerTest(
|
|||
media.copy(
|
||||
status = Media.Status.READY,
|
||||
pages = (1..10).map { BookPage("$it", "image/jpeg") },
|
||||
pageCount = 10,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue