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);
|
||||
}
|
||||
}
|
||||
@@ -60,4 +60,20 @@ class KoreaderUserControllerTest {
|
||||
assertEquals(HttpStatus.NO_CONTENT, resp.getStatusCode());
|
||||
assertNull(resp.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toggleSyncProgressWithWebReader_returnsNoContent() {
|
||||
doNothing().when(koreaderUserService).toggleSyncProgressWithWebReader(true);
|
||||
ResponseEntity<Void> resp = controller.toggleSyncProgressWithWebReader(true);
|
||||
assertEquals(HttpStatus.NO_CONTENT, resp.getStatusCode());
|
||||
assertNull(resp.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toggleSyncProgressWithBooklore_delegatesToWebReader_andReturnsNoContent() {
|
||||
doNothing().when(koreaderUserService).toggleSyncProgressWithWebReader(true);
|
||||
ResponseEntity<Void> resp = controller.toggleSyncProgressWithBooklore(true);
|
||||
assertEquals(HttpStatus.NO_CONTENT, resp.getStatusCode());
|
||||
assertNull(resp.getBody());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ class KoreaderUserServiceTest {
|
||||
|
||||
when(koreaderUserMapper.toDto(any(KoreaderUserEntity.class))).thenAnswer(invocation -> {
|
||||
KoreaderUserEntity u = invocation.getArgument(0);
|
||||
return new KoreaderUser(u.getId(), u.getUsername(), u.getPassword(), u.getPasswordMD5(), u.isSyncEnabled(), u.isSyncWithBookloreReader());
|
||||
return new KoreaderUser(u.getId(), u.getUsername(), u.getPassword(), u.getPasswordMD5(), u.isSyncEnabled(), u.isSyncWithWebReader());
|
||||
});
|
||||
|
||||
KoreaderUser result = service.upsertUser("userA", "passA");
|
||||
|
||||
+4
-4
@@ -51,10 +51,10 @@
|
||||
<div class="setting-label-row">
|
||||
<span class="setting-label">{{ t('koreader.syncWithGrimmory') }}</span>
|
||||
<p-toggle-switch
|
||||
name="syncWithGrimmoryReader"
|
||||
[(ngModel)]="syncWithGrimmoryReader"
|
||||
(ngModelChange)="onToggleSyncWithGrimmoryReader($event)"
|
||||
inputId="syncWithGrimmoryReader"
|
||||
name="syncWithWebReader"
|
||||
[(ngModel)]="syncWithWebReader"
|
||||
(ngModelChange)="onToggleSyncWithWebReader($event)"
|
||||
inputId="syncWithWebReader"
|
||||
[disabled]="!credentialsSaved || !koReaderSyncEnabled">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
|
||||
+5
-5
@@ -33,7 +33,7 @@ export class KoreaderSettingsComponent {
|
||||
editMode = true;
|
||||
showPassword = false;
|
||||
koReaderSyncEnabled = false;
|
||||
syncWithGrimmoryReader = false;
|
||||
syncWithWebReader = false;
|
||||
koReaderUsername = '';
|
||||
koReaderPassword = '';
|
||||
credentialsSaved = false;
|
||||
@@ -70,7 +70,7 @@ export class KoreaderSettingsComponent {
|
||||
this.koReaderUsername = koreaderUser.username;
|
||||
this.koReaderPassword = koreaderUser.password;
|
||||
this.koReaderSyncEnabled = koreaderUser.syncEnabled;
|
||||
this.syncWithGrimmoryReader = koreaderUser.syncWithGrimmoryReader ?? koreaderUser.syncWithBookloreReader ?? false;
|
||||
this.syncWithWebReader = koreaderUser.syncWithWebReader ?? false;
|
||||
this.credentialsSaved = true;
|
||||
},
|
||||
error: err => {
|
||||
@@ -113,12 +113,12 @@ export class KoreaderSettingsComponent {
|
||||
});
|
||||
}
|
||||
|
||||
onToggleSyncWithGrimmoryReader(enabled: boolean) {
|
||||
this.koreaderService.toggleSyncProgressWithGrimmoryReader(enabled).pipe(
|
||||
onToggleSyncWithWebReader(enabled: boolean) {
|
||||
this.koreaderService.toggleSyncProgressWithWebReader(enabled).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.syncWithGrimmoryReader = enabled;
|
||||
this.syncWithWebReader = enabled;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsDevice.koreader.syncUpdated'),
|
||||
|
||||
+8
-13
@@ -69,14 +69,14 @@ describe('KoreaderService', () => {
|
||||
username: 'reader',
|
||||
password: 'secret123',
|
||||
syncEnabled: false,
|
||||
syncWithGrimmoryReader: true,
|
||||
syncWithWebReader: true,
|
||||
});
|
||||
|
||||
expect(responseBody).toEqual({
|
||||
username: 'reader',
|
||||
password: 'secret123',
|
||||
syncEnabled: false,
|
||||
syncWithGrimmoryReader: true,
|
||||
syncWithWebReader: true,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -91,24 +91,19 @@ describe('KoreaderService', () => {
|
||||
request.flush(null);
|
||||
});
|
||||
|
||||
it('uses the Grimmory sync-progress endpoint before falling back to the legacy Booklore route', () => {
|
||||
it('patches the web-reader sync-progress toggle using the enabled query parameter', () => {
|
||||
let completed = false;
|
||||
|
||||
service.toggleSyncProgressWithGrimmoryReader(false).subscribe(() => {
|
||||
service.toggleSyncProgressWithWebReader(false).subscribe(() => {
|
||||
completed = true;
|
||||
});
|
||||
|
||||
const grimmoryRequest = httpTestingController.expectOne(req =>
|
||||
const request = httpTestingController.expectOne(req =>
|
||||
req.method === 'PATCH' && req.url.endsWith('/api/v1/koreader-users/me/sync-progress-with-grimmory')
|
||||
);
|
||||
expect(grimmoryRequest.request.params.get('enabled')).toBe('false');
|
||||
grimmoryRequest.flush('missing route', {status: 404, statusText: 'Not Found'});
|
||||
|
||||
const legacyRequest = httpTestingController.expectOne(req =>
|
||||
req.method === 'PATCH' && req.url.endsWith('/api/v1/koreader-users/me/sync-progress-with-booklore')
|
||||
);
|
||||
expect(legacyRequest.request.params.get('enabled')).toBe('false');
|
||||
legacyRequest.flush(null);
|
||||
expect(request.request.params.get('enabled')).toBe('false');
|
||||
expect(request.request.body).toBeNull();
|
||||
request.flush(null);
|
||||
|
||||
expect(completed).toBe(true);
|
||||
});
|
||||
|
||||
+3
-11
@@ -2,16 +2,13 @@ import {inject, Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../../../core/config/api-config';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
|
||||
|
||||
export interface KoreaderUser {
|
||||
username: string;
|
||||
password: string;
|
||||
syncEnabled: boolean;
|
||||
syncWithGrimmoryReader?: boolean;
|
||||
// TODO(grimmory-cleanup): Remove once the backend no longer returns the legacy Booklore KOReader sync field.
|
||||
syncWithBookloreReader?: boolean;
|
||||
syncWithWebReader?: boolean;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
@@ -38,14 +35,9 @@ export class KoreaderService {
|
||||
});
|
||||
}
|
||||
|
||||
toggleSyncProgressWithGrimmoryReader(enabled: boolean): Observable<void> {
|
||||
toggleSyncProgressWithWebReader(enabled: boolean): Observable<void> {
|
||||
return this.http.patch<void>(`${this.url}/me/sync-progress-with-grimmory`, null, {
|
||||
params: {enabled: enabled.toString()}
|
||||
}).pipe(
|
||||
// TODO(grimmory-cleanup): Remove the legacy endpoint fallback after all supported backends expose the Grimmory route.
|
||||
catchError(() => this.http.patch<void>(`${this.url}/me/sync-progress-with-booklore`, null, {
|
||||
params: {enabled: enabled.toString()}
|
||||
}))
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user