chore: make two-way progress sync always-on (#2734)
This commit is contained in:
@@ -71,7 +71,6 @@ public class KoreaderAuthFilter extends OncePerRequestFilter {
|
||||
user.getUsername(),
|
||||
user.getPasswordMD5(),
|
||||
user.isSyncEnabled(),
|
||||
user.isSyncWithWebReader(),
|
||||
bookLoreUserId,
|
||||
List.of(new SimpleGrantedAuthority("ROLE_USER"))
|
||||
);
|
||||
|
||||
+1
-4
@@ -13,16 +13,13 @@ public class KoreaderUserDetails implements UserDetails {
|
||||
@Getter
|
||||
private final boolean syncEnabled;
|
||||
@Getter
|
||||
private final boolean syncWithWebReader;
|
||||
@Getter
|
||||
private final Long bookLoreUserId;
|
||||
private final Collection<? extends GrantedAuthority> authorities;
|
||||
|
||||
public KoreaderUserDetails(String username, String password, boolean syncEnabled, boolean syncWithWebReader, Long bookLoreUserId, Collection<? extends GrantedAuthority> authorities) {
|
||||
public KoreaderUserDetails(String username, String password, boolean syncEnabled, Long bookLoreUserId, Collection<? extends GrantedAuthority> authorities) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.syncEnabled = syncEnabled;
|
||||
this.syncWithWebReader = syncWithWebReader;
|
||||
this.bookLoreUserId = bookLoreUserId;
|
||||
this.authorities = authorities;
|
||||
}
|
||||
|
||||
@@ -50,27 +50,4 @@ public class KoreaderUserController {
|
||||
koreaderUserService.toggleSync(enabled);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Toggle sync progress with web reader", description = "Enable or disable syncing reading progress with the web reader.")
|
||||
@ApiResponse(responseCode = "204", description = "Sync progress toggled successfully")
|
||||
@PatchMapping("/me/sync-progress-with-grimmory")
|
||||
@PreAuthorize("@securityUtil.canSyncKoReader() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Void> toggleSyncProgressWithWebReader(
|
||||
@Parameter(description = "Enable or disable sync progress") @RequestParam boolean enabled) {
|
||||
koreaderUserService.toggleSyncProgressWithWebReader(enabled);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(
|
||||
summary = "[Deprecated] Toggle sync progress with web reader",
|
||||
description = "Deprecated alias for /me/sync-progress-with-grimmory. Use the new endpoint; this one will be removed in a future release.",
|
||||
deprecated = true)
|
||||
@ApiResponse(responseCode = "204", description = "Sync progress toggled successfully")
|
||||
@PatchMapping("/me/sync-progress-with-booklore")
|
||||
@PreAuthorize("@securityUtil.canSyncKoReader() or @securityUtil.isAdmin()")
|
||||
@Deprecated(forRemoval = true)
|
||||
public ResponseEntity<Void> toggleSyncProgressWithBooklore(
|
||||
@Parameter(description = "Enable or disable sync progress") @RequestParam boolean enabled) {
|
||||
return toggleSyncProgressWithWebReader(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,5 +14,4 @@ public class KoboSyncSettings {
|
||||
private boolean autoAddToShelf;
|
||||
private String hardcoverApiKey;
|
||||
private boolean hardcoverSyncEnabled;
|
||||
private boolean twoWayProgressSync;
|
||||
}
|
||||
|
||||
@@ -12,5 +12,4 @@ public class KoreaderUser {
|
||||
private String password;
|
||||
private String passwordMD5;
|
||||
private boolean syncEnabled;
|
||||
private boolean syncWithWebReader;
|
||||
}
|
||||
|
||||
@@ -44,8 +44,4 @@ public class KoboUserSettingsEntity {
|
||||
@Column(name = "hardcover_sync_enabled")
|
||||
@Builder.Default
|
||||
private boolean hardcoverSyncEnabled = false;
|
||||
|
||||
@Column(name = "two_way_progress_sync")
|
||||
@Builder.Default
|
||||
private boolean twoWayProgressSync = false;
|
||||
}
|
||||
|
||||
@@ -38,10 +38,6 @@ public class KoreaderUserEntity {
|
||||
@Builder.Default
|
||||
private boolean syncEnabled = false;
|
||||
|
||||
@Column(name = "sync_with_booklore_reader", nullable = false)
|
||||
@Builder.Default
|
||||
private boolean syncWithWebReader = false;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "booklore_user_id")
|
||||
private BookLoreUserEntity bookLoreUser;
|
||||
|
||||
@@ -221,8 +221,7 @@ public class KoboEntitlementService {
|
||||
Map<Long, KoboSpanPositionMap> preloadedMaps) {
|
||||
String entitlementId = String.valueOf(progress.getBook().getId());
|
||||
|
||||
boolean twoWaySync = koboSettingsService.getCurrentUserSettings().isTwoWayProgressSync();
|
||||
KoboReadingState.CurrentBookmark bookmark = (progress.getKoboProgressPercent() != null || (twoWaySync && progress.getEpubProgressPercent() != null))
|
||||
KoboReadingState.CurrentBookmark bookmark = (progress.getKoboProgressPercent() != null || (progress.getEpubProgressPercent() != null))
|
||||
? readingStateBuilder.buildBookmarkFromProgress(progress, fileProgress, now, preloadedMaps)
|
||||
: readingStateBuilder.buildEmptyBookmark(now);
|
||||
|
||||
@@ -259,21 +258,17 @@ public class KoboEntitlementService {
|
||||
.findByUserIdAndBookIdForKoboSync(userId, book.getId());
|
||||
UserBookFileProgressEntity fileProgress = findSyncedEpubFileProgress(userId, book).orElse(null);
|
||||
|
||||
boolean twoWaySync = koboSettingsService.getCurrentUserSettings().isTwoWayProgressSync();
|
||||
|
||||
KoboReadingState.CurrentBookmark webReaderBookmark = twoWaySync
|
||||
? userProgress
|
||||
KoboReadingState.CurrentBookmark webReaderBookmark = userProgress
|
||||
.filter(readingStateBuilder::shouldUseWebReaderProgress)
|
||||
.map(progress -> readingStateBuilder.buildBookmarkFromProgress(progress, fileProgress, now))
|
||||
.orElse(null)
|
||||
: null;
|
||||
.orElse(null);
|
||||
|
||||
KoboReadingState.CurrentBookmark bookmark = webReaderBookmark != null
|
||||
? webReaderBookmark
|
||||
: existingState != null && existingState.getCurrentBookmark() != null
|
||||
? existingState.getCurrentBookmark()
|
||||
: userProgress
|
||||
.filter(progress -> progress.getKoboProgressPercent() != null || (twoWaySync && progress.getEpubProgressPercent() != null))
|
||||
.filter(progress -> progress.getKoboProgressPercent() != null || (progress.getEpubProgressPercent() != null))
|
||||
.map(progress -> readingStateBuilder.buildBookmarkFromProgress(progress, fileProgress, now))
|
||||
.orElseGet(() -> readingStateBuilder.buildEmptyBookmark(now));
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ public class KoboLibrarySyncService {
|
||||
private final UserBookProgressRepository userBookProgressRepository;
|
||||
private final KoboServerProxy koboServerProxy;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final KoboSettingsService koboSettingsService;
|
||||
private final AppSettingService appSettingService;
|
||||
|
||||
private Collection<Entitlement> getEntitlementsFromKoboStoreResponse(ResponseEntity<JsonNode> koboStoreResponse) {
|
||||
@@ -182,12 +181,6 @@ public class KoboLibrarySyncService {
|
||||
List<UserBookProgressEntity> booksNeedingSync =
|
||||
userBookProgressRepository.findAllBooksNeedingKoboSync(userId, snapshotId);
|
||||
|
||||
if (!koboSettingsService.getCurrentUserSettings().isTwoWayProgressSync()) {
|
||||
booksNeedingSync = booksNeedingSync.stream()
|
||||
.filter(p -> needsStatusSync(p) || needsKoboProgressSync(p))
|
||||
.toList();
|
||||
}
|
||||
|
||||
if (booksNeedingSync.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -229,8 +222,7 @@ public class KoboLibrarySyncService {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (koboSettingsService.getCurrentUserSettings().isTwoWayProgressSync()
|
||||
&& progress.getEpubProgressPercent() != null) {
|
||||
if (progress.getEpubProgressPercent() != null) {
|
||||
Instant sentTime = progress.getKoboProgressSentTime();
|
||||
Instant lastReadTime = progress.getLastReadTime();
|
||||
if (lastReadTime != null && (sentTime == null || lastReadTime.isAfter(sentTime))) {
|
||||
|
||||
@@ -55,9 +55,6 @@ public class KoboReadingStateBuilder {
|
||||
}
|
||||
|
||||
public boolean shouldUseWebReaderProgress(UserBookProgressEntity progress) {
|
||||
if (!koboSettingsService.getCurrentUserSettings().isTwoWayProgressSync()) {
|
||||
return false;
|
||||
}
|
||||
if (progress.getEpubProgressPercent() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -151,9 +151,6 @@ public class KoboReadingStateService {
|
||||
}
|
||||
|
||||
private void overlayWebReaderBookmark(KoboReadingState state, String entitlementId, Long userId) {
|
||||
if (!koboSettingsService.getCurrentUserSettings().isTwoWayProgressSync()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Long bookId = Long.parseLong(entitlementId);
|
||||
UserBookFileProgressEntity fileProgress = findSyncedEpubFileProgress(userId, bookId).orElse(null);
|
||||
@@ -171,9 +168,8 @@ public class KoboReadingStateService {
|
||||
Long bookId = Long.parseLong(entitlementId);
|
||||
BookLoreUser user = authenticationService.getAuthenticatedUser();
|
||||
|
||||
boolean twoWaySync = koboSettingsService.getCurrentUserSettings().isTwoWayProgressSync();
|
||||
return progressRepository.findByUserIdAndBookIdForKoboSync(user.getId(), bookId)
|
||||
.filter(progress -> progress.getKoboProgressPercent() != null || progress.getKoboLocation() != null || (twoWaySync && progress.getEpubProgressPercent() != null))
|
||||
.filter(progress -> progress.getKoboProgressPercent() != null || progress.getKoboLocation() != null || (progress.getEpubProgressPercent() != null))
|
||||
.map(progress -> readingStateBuilder.buildReadingStateFromProgress(
|
||||
entitlementId,
|
||||
progress,
|
||||
@@ -271,10 +267,6 @@ public class KoboReadingStateService {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!koboSettingsService.getCurrentUserSettings().isTwoWayProgressSync()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean webReaderIsNewer = existingFileProgress != null
|
||||
&& existingFileProgress.getLastReadTime() != null
|
||||
&& bookmarkTime != null
|
||||
@@ -326,7 +318,7 @@ public class KoboReadingStateService {
|
||||
}
|
||||
|
||||
private boolean isWebReaderNewerThanBookmark(UserBookFileProgressEntity fileProgress, Instant bookmarkTime) {
|
||||
if (bookmarkTime == null || !koboSettingsService.getCurrentUserSettings().isTwoWayProgressSync()) {
|
||||
if (bookmarkTime == null) {
|
||||
return false;
|
||||
}
|
||||
return fileProgress != null
|
||||
|
||||
@@ -84,7 +84,6 @@ public class KoboSettingsService {
|
||||
}
|
||||
|
||||
entity.setAutoAddToShelf(settings.isAutoAddToShelf());
|
||||
entity.setTwoWayProgressSync(settings.isTwoWayProgressSync());
|
||||
|
||||
repository.save(entity);
|
||||
return mapToDto(entity, hardcoverSyncSettingsService.getSettingsForUserId(user.getId()));
|
||||
@@ -131,7 +130,6 @@ public class KoboSettingsService {
|
||||
dto.setProgressMarkAsReadingThreshold(entity.getProgressMarkAsReadingThreshold());
|
||||
dto.setProgressMarkAsFinishedThreshold(entity.getProgressMarkAsFinishedThreshold());
|
||||
dto.setAutoAddToShelf(entity.isAutoAddToShelf());
|
||||
dto.setTwoWayProgressSync(entity.isTwoWayProgressSync());
|
||||
if (hardcoverSettings != null) {
|
||||
dto.setHardcoverApiKey(hardcoverSettings.getHardcoverApiKey());
|
||||
dto.setHardcoverSyncEnabled(hardcoverSettings.isHardcoverSyncEnabled());
|
||||
|
||||
@@ -85,7 +85,7 @@ public class KoreaderService {
|
||||
UserBookProgressEntity userProgress = getOrCreateUserProgress(user, book);
|
||||
Float previousProgressPercent = userProgress.getKoreaderProgressPercent();
|
||||
ReadStatus previousReadStatus = userProgress.getReadStatus();
|
||||
updateProgressData(userProgress, koProgress, authDetails.isSyncWithWebReader(), book);
|
||||
updateProgressData(userProgress, koProgress, book);
|
||||
|
||||
progressRepository.save(userProgress);
|
||||
|
||||
@@ -108,7 +108,6 @@ public class KoreaderService {
|
||||
try {
|
||||
koreaderUserRepository.findByBookLoreUserId(userId)
|
||||
.filter(KoreaderUserEntity::isSyncEnabled)
|
||||
.filter(KoreaderUserEntity::isSyncWithWebReader)
|
||||
.ifPresent(koreaderUser -> {
|
||||
BookEntity book = bookRepository.findById(bookId).orElse(null);
|
||||
BookLoreUserEntity user = userRepository.findById(userId).orElse(null);
|
||||
@@ -183,14 +182,14 @@ public class KoreaderService {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateProgressData(UserBookProgressEntity userProgress, KoreaderProgress koProgress, boolean syncWithWebReader, BookEntity book) {
|
||||
private void updateProgressData(UserBookProgressEntity userProgress, KoreaderProgress koProgress, BookEntity book) {
|
||||
userProgress.setKoreaderProgress(koProgress.getProgress());
|
||||
userProgress.setKoreaderProgressPercent(koProgress.getPercentage());
|
||||
userProgress.setKoreaderDevice(koProgress.getDevice());
|
||||
userProgress.setKoreaderDeviceId(koProgress.getDevice_id());
|
||||
userProgress.setKoreaderLastSyncTime(Instant.now());
|
||||
userProgress.setLastReadTime(Instant.now());
|
||||
if (syncWithWebReader && koProgress.getProgress() != null) {
|
||||
if (koProgress.getProgress() != null) {
|
||||
try {
|
||||
String cfi = epubCfiService.convertXPointerToCfi(book.getFullFilePath(), koProgress.getProgress());
|
||||
|
||||
|
||||
@@ -70,13 +70,4 @@ public class KoreaderUserService {
|
||||
user.setSyncEnabled(enabled);
|
||||
koreaderUserRepository.save(user);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void toggleSyncProgressWithWebReader(boolean enabled) {
|
||||
Long id = authService.getAuthenticatedUser().getId();
|
||||
KoreaderUserEntity user = koreaderUserRepository.findByBookLoreUserId(id)
|
||||
.orElseThrow(() -> ApiError.GENERIC_NOT_FOUND.createException("Koreader user not found for BookLore user ID: " + id));
|
||||
user.setSyncWithWebReader(enabled);
|
||||
koreaderUserRepository.save(user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE koreader_user DROP COLUMN sync_with_booklore_reader;
|
||||
ALTER TABLE kobo_user_settings DROP COLUMN two_way_progress_sync;
|
||||
|
||||
Reference in New Issue
Block a user