Skip to content

Commit

Permalink
fix(api): properly handle simple read progress for divina compatible …
Browse files Browse the repository at this point in the history
…epub
  • Loading branch information
gotson committed Aug 26, 2024
1 parent cf489fd commit 1fef82f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ interface MediaRepository {
pageHashing: Int,
): Collection<String>

fun getPagesSize(bookId: String): Int

fun getPagesSizes(bookIds: Collection<String>): Collection<Pair<String, Int>>

fun findExtensionByIdOrNull(bookId: String): MediaExtension?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,23 @@ class BookLifecycle(
user: KomgaUser,
page: Int,
) {
val pages = mediaRepository.getPagesSize(book.id)
require(page in 1..pages) { "Page argument ($page) must be within 1 and book page count ($pages)" }
val media = mediaRepository.findById(book.id)
require(page in 1..media.pageCount) { "Page argument ($page) must be within 1 and book page count (${media.pageCount})" }

val locator =
if (media.profile == MediaProfile.EPUB) {
require(media.epubDivinaCompatible) { "epub book is not Divina compatible" }

val extension =
mediaRepository.findExtensionByIdOrNull(book.id) as? MediaExtensionEpub
?: throw IllegalArgumentException("Epub extension not found")
extension.positions[page - 1]
} else {
null
}

val progress = ReadProgress(book.id, user.id, page, page == media.pageCount, locator = locator)

val progress = ReadProgress(book.id, user.id, page, page == pages)
readProgressRepository.save(progress)
eventPublisher.publishEvent(DomainEvent.ReadProgressChanged(progress))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ class MediaDao(
.map { it.value1() }
}

override fun getPagesSize(bookId: String): Int =
dsl.select(m.PAGE_COUNT)
.from(m)
.where(m.BOOK_ID.eq(bookId))
.fetch(m.PAGE_COUNT)
.first()

override fun getPagesSizes(bookIds: Collection<String>): Collection<Pair<String, Int>> =
dsl.select(m.BOOK_ID, m.PAGE_COUNT)
.from(m)
Expand Down

0 comments on commit 1fef82f

Please sign in to comment.