refactor(api): rename KOReader sync references from booklore to grimmory (#1085)
This commit is contained in:
@@ -71,7 +71,7 @@ public class KoreaderAuthFilter extends OncePerRequestFilter {
|
||||
user.getUsername(),
|
||||
user.getPasswordMD5(),
|
||||
user.isSyncEnabled(),
|
||||
user.isSyncWithBookloreReader(),
|
||||
user.isSyncWithWebReader(),
|
||||
bookLoreUserId,
|
||||
List.of(new SimpleGrantedAuthority("ROLE_USER"))
|
||||
);
|
||||
@@ -81,4 +81,4 @@ public class KoreaderAuthFilter extends OncePerRequestFilter {
|
||||
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -13,16 +13,16 @@ public class KoreaderUserDetails implements UserDetails {
|
||||
@Getter
|
||||
private final boolean syncEnabled;
|
||||
@Getter
|
||||
private final boolean syncWithBookloreReader;
|
||||
private final boolean syncWithWebReader;
|
||||
@Getter
|
||||
private final Long bookLoreUserId;
|
||||
private final Collection<? extends GrantedAuthority> authorities;
|
||||
|
||||
public KoreaderUserDetails(String username, String password, boolean syncEnabled, boolean syncWithBookloreReader, Long bookLoreUserId, Collection<? extends GrantedAuthority> authorities) {
|
||||
public KoreaderUserDetails(String username, String password, boolean syncEnabled, boolean syncWithWebReader, Long bookLoreUserId, Collection<? extends GrantedAuthority> authorities) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.syncEnabled = syncEnabled;
|
||||
this.syncWithBookloreReader = syncWithBookloreReader;
|
||||
this.syncWithWebReader = syncWithWebReader;
|
||||
this.bookLoreUserId = bookLoreUserId;
|
||||
this.authorities = authorities;
|
||||
}
|
||||
|
||||
@@ -51,13 +51,26 @@ public class KoreaderUserController {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Toggle sync progress with Booklore reader", description = "Enable or disable syncing reading progress with Booklore reader.")
|
||||
@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) {
|
||||
koreaderUserService.toggleSyncProgressWithBooklore(enabled);
|
||||
return ResponseEntity.noContent().build();
|
||||
return toggleSyncProgressWithWebReader(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,5 +12,5 @@ public class KoreaderUser {
|
||||
private String password;
|
||||
private String passwordMD5;
|
||||
private boolean syncEnabled;
|
||||
private boolean syncWithBookloreReader;
|
||||
private boolean syncWithWebReader;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class KoreaderUserEntity {
|
||||
|
||||
@Column(name = "sync_with_booklore_reader", nullable = false)
|
||||
@Builder.Default
|
||||
private boolean syncWithBookloreReader = false;
|
||||
private boolean syncWithWebReader = false;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "booklore_user_id")
|
||||
|
||||
@@ -74,7 +74,7 @@ public class KoreaderService {
|
||||
UserBookProgressEntity userProgress = getOrCreateUserProgress(user, book);
|
||||
Float previousProgressPercent = userProgress.getKoreaderProgressPercent();
|
||||
ReadStatus previousReadStatus = userProgress.getReadStatus();
|
||||
updateProgressData(userProgress, koProgress, authDetails.isSyncWithBookloreReader(), book);
|
||||
updateProgressData(userProgress, koProgress, authDetails.isSyncWithWebReader(), book);
|
||||
|
||||
progressRepository.save(userProgress);
|
||||
|
||||
@@ -128,14 +128,14 @@ public class KoreaderService {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateProgressData(UserBookProgressEntity userProgress, KoreaderProgress koProgress, boolean syncWithBookloreReader, BookEntity book) {
|
||||
private void updateProgressData(UserBookProgressEntity userProgress, KoreaderProgress koProgress, boolean syncWithWebReader, 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 (syncWithBookloreReader && koProgress.getProgress() != null) {
|
||||
if (syncWithWebReader && koProgress.getProgress() != null) {
|
||||
try {
|
||||
String cfi = epubCfiService.convertXPointerToCfi(book.getFullFilePath(), koProgress.getProgress());
|
||||
|
||||
|
||||
@@ -72,11 +72,11 @@ public class KoreaderUserService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void toggleSyncProgressWithBooklore(boolean enabled) {
|
||||
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.setSyncWithBookloreReader(enabled);
|
||||
user.setSyncWithWebReader(enabled);
|
||||
koreaderUserRepository.save(user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user