fix(api): read progress modified time could be inaccurate in some cases

This commit is contained in:
Gauthier Roebroeck 2025-01-09 15:39:20 +08:00
parent 623b2e3687
commit 6c3565caa8

View file

@ -34,7 +34,6 @@ import org.gotson.komga.infrastructure.hash.Hasher
import org.gotson.komga.infrastructure.hash.KoreaderHasher import org.gotson.komga.infrastructure.hash.KoreaderHasher
import org.gotson.komga.infrastructure.image.ImageConverter import org.gotson.komga.infrastructure.image.ImageConverter
import org.gotson.komga.infrastructure.image.ImageType import org.gotson.komga.infrastructure.image.ImageType
import org.gotson.komga.language.toCurrentTimeZone
import org.springframework.beans.factory.annotation.Qualifier import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.context.ApplicationEventPublisher import org.springframework.context.ApplicationEventPublisher
import org.springframework.data.domain.Pageable import org.springframework.data.domain.Pageable
@ -43,6 +42,7 @@ import org.springframework.transaction.support.TransactionTemplate
import org.springframework.web.util.UriUtils import org.springframework.web.util.UriUtils
import java.io.File import java.io.File
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.ZoneId
import kotlin.io.path.deleteIfExists import kotlin.io.path.deleteIfExists
import kotlin.io.path.exists import kotlin.io.path.exists
import kotlin.io.path.isWritable import kotlin.io.path.isWritable
@ -458,8 +458,8 @@ class BookLifecycle(
readProgressRepository.findByBookIdAndUserIdOrNull(book.id, user.id)?.let { savedProgress -> readProgressRepository.findByBookIdAndUserIdOrNull(book.id, user.id)?.let { savedProgress ->
check( check(
newProgression.modified newProgression.modified
.withZoneSameInstant(ZoneId.systemDefault())
.toLocalDateTime() .toLocalDateTime()
.toCurrentTimeZone()
.isAfter(savedProgress.readDate), .isAfter(savedProgress.readDate),
) { "Progression is older than existing" } ) { "Progression is older than existing" }
} }
@ -477,7 +477,7 @@ class BookLifecycle(
user.id, user.id,
newProgression.locator.locations!!.position!!, newProgression.locator.locations!!.position!!,
newProgression.locator.locations.position == media.pageCount, newProgression.locator.locations.position == media.pageCount,
newProgression.modified.toLocalDateTime().toCurrentTimeZone(), newProgression.modified.withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime(),
newProgression.device.id, newProgression.device.id,
newProgression.device.name, newProgression.device.name,
newProgression.locator, newProgression.locator,
@ -518,7 +518,7 @@ class BookLifecycle(
user.id, user.id,
totalProgression?.let { (media.pageCount * it).roundToInt() } ?: 0, totalProgression?.let { (media.pageCount * it).roundToInt() } ?: 0,
totalProgression?.let { it >= 0.99F } ?: false, totalProgression?.let { it >= 0.99F } ?: false,
newProgression.modified.toLocalDateTime().toCurrentTimeZone(), newProgression.modified.withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime(),
newProgression.device.id, newProgression.device.id,
newProgression.device.name, newProgression.device.name,
newProgression.locator.copy( newProgression.locator.copy(