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.getUsername(),
|
||||||
user.getPasswordMD5(),
|
user.getPasswordMD5(),
|
||||||
user.isSyncEnabled(),
|
user.isSyncEnabled(),
|
||||||
user.isSyncWithBookloreReader(),
|
user.isSyncWithWebReader(),
|
||||||
bookLoreUserId,
|
bookLoreUserId,
|
||||||
List.of(new SimpleGrantedAuthority("ROLE_USER"))
|
List.of(new SimpleGrantedAuthority("ROLE_USER"))
|
||||||
);
|
);
|
||||||
@@ -81,4 +81,4 @@ public class KoreaderAuthFilter extends OncePerRequestFilter {
|
|||||||
|
|
||||||
chain.doFilter(request, response);
|
chain.doFilter(request, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -13,16 +13,16 @@ public class KoreaderUserDetails implements UserDetails {
|
|||||||
@Getter
|
@Getter
|
||||||
private final boolean syncEnabled;
|
private final boolean syncEnabled;
|
||||||
@Getter
|
@Getter
|
||||||
private final boolean syncWithBookloreReader;
|
private final boolean syncWithWebReader;
|
||||||
@Getter
|
@Getter
|
||||||
private final Long bookLoreUserId;
|
private final Long bookLoreUserId;
|
||||||
private final Collection<? extends GrantedAuthority> authorities;
|
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.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.syncEnabled = syncEnabled;
|
this.syncEnabled = syncEnabled;
|
||||||
this.syncWithBookloreReader = syncWithBookloreReader;
|
this.syncWithWebReader = syncWithWebReader;
|
||||||
this.bookLoreUserId = bookLoreUserId;
|
this.bookLoreUserId = bookLoreUserId;
|
||||||
this.authorities = authorities;
|
this.authorities = authorities;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,13 +51,26 @@ public class KoreaderUserController {
|
|||||||
return ResponseEntity.noContent().build();
|
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")
|
@ApiResponse(responseCode = "204", description = "Sync progress toggled successfully")
|
||||||
@PatchMapping("/me/sync-progress-with-booklore")
|
@PatchMapping("/me/sync-progress-with-booklore")
|
||||||
@PreAuthorize("@securityUtil.canSyncKoReader() or @securityUtil.isAdmin()")
|
@PreAuthorize("@securityUtil.canSyncKoReader() or @securityUtil.isAdmin()")
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public ResponseEntity<Void> toggleSyncProgressWithBooklore(
|
public ResponseEntity<Void> toggleSyncProgressWithBooklore(
|
||||||
@Parameter(description = "Enable or disable sync progress") @RequestParam boolean enabled) {
|
@Parameter(description = "Enable or disable sync progress") @RequestParam boolean enabled) {
|
||||||
koreaderUserService.toggleSyncProgressWithBooklore(enabled);
|
return toggleSyncProgressWithWebReader(enabled);
|
||||||
return ResponseEntity.noContent().build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ public class KoreaderUser {
|
|||||||
private String password;
|
private String password;
|
||||||
private String passwordMD5;
|
private String passwordMD5;
|
||||||
private boolean syncEnabled;
|
private boolean syncEnabled;
|
||||||
private boolean syncWithBookloreReader;
|
private boolean syncWithWebReader;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class KoreaderUserEntity {
|
|||||||
|
|
||||||
@Column(name = "sync_with_booklore_reader", nullable = false)
|
@Column(name = "sync_with_booklore_reader", nullable = false)
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private boolean syncWithBookloreReader = false;
|
private boolean syncWithWebReader = false;
|
||||||
|
|
||||||
@OneToOne(fetch = FetchType.LAZY)
|
@OneToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "booklore_user_id")
|
@JoinColumn(name = "booklore_user_id")
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class KoreaderService {
|
|||||||
UserBookProgressEntity userProgress = getOrCreateUserProgress(user, book);
|
UserBookProgressEntity userProgress = getOrCreateUserProgress(user, book);
|
||||||
Float previousProgressPercent = userProgress.getKoreaderProgressPercent();
|
Float previousProgressPercent = userProgress.getKoreaderProgressPercent();
|
||||||
ReadStatus previousReadStatus = userProgress.getReadStatus();
|
ReadStatus previousReadStatus = userProgress.getReadStatus();
|
||||||
updateProgressData(userProgress, koProgress, authDetails.isSyncWithBookloreReader(), book);
|
updateProgressData(userProgress, koProgress, authDetails.isSyncWithWebReader(), book);
|
||||||
|
|
||||||
progressRepository.save(userProgress);
|
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.setKoreaderProgress(koProgress.getProgress());
|
||||||
userProgress.setKoreaderProgressPercent(koProgress.getPercentage());
|
userProgress.setKoreaderProgressPercent(koProgress.getPercentage());
|
||||||
userProgress.setKoreaderDevice(koProgress.getDevice());
|
userProgress.setKoreaderDevice(koProgress.getDevice());
|
||||||
userProgress.setKoreaderDeviceId(koProgress.getDevice_id());
|
userProgress.setKoreaderDeviceId(koProgress.getDevice_id());
|
||||||
userProgress.setKoreaderLastSyncTime(Instant.now());
|
userProgress.setKoreaderLastSyncTime(Instant.now());
|
||||||
userProgress.setLastReadTime(Instant.now());
|
userProgress.setLastReadTime(Instant.now());
|
||||||
if (syncWithBookloreReader && koProgress.getProgress() != null) {
|
if (syncWithWebReader && koProgress.getProgress() != null) {
|
||||||
try {
|
try {
|
||||||
String cfi = epubCfiService.convertXPointerToCfi(book.getFullFilePath(), koProgress.getProgress());
|
String cfi = epubCfiService.convertXPointerToCfi(book.getFullFilePath(), koProgress.getProgress());
|
||||||
|
|
||||||
|
|||||||
@@ -72,11 +72,11 @@ public class KoreaderUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void toggleSyncProgressWithBooklore(boolean enabled) {
|
public void toggleSyncProgressWithWebReader(boolean enabled) {
|
||||||
Long id = authService.getAuthenticatedUser().getId();
|
Long id = authService.getAuthenticatedUser().getId();
|
||||||
KoreaderUserEntity user = koreaderUserRepository.findByBookLoreUserId(id)
|
KoreaderUserEntity user = koreaderUserRepository.findByBookLoreUserId(id)
|
||||||
.orElseThrow(() -> ApiError.GENERIC_NOT_FOUND.createException("Koreader user not found for BookLore user ID: " + 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);
|
koreaderUserRepository.save(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,4 +60,20 @@ class KoreaderUserControllerTest {
|
|||||||
assertEquals(HttpStatus.NO_CONTENT, resp.getStatusCode());
|
assertEquals(HttpStatus.NO_CONTENT, resp.getStatusCode());
|
||||||
assertNull(resp.getBody());
|
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 -> {
|
when(koreaderUserMapper.toDto(any(KoreaderUserEntity.class))).thenAnswer(invocation -> {
|
||||||
KoreaderUserEntity u = invocation.getArgument(0);
|
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");
|
KoreaderUser result = service.upsertUser("userA", "passA");
|
||||||
|
|||||||
+4
-4
@@ -51,10 +51,10 @@
|
|||||||
<div class="setting-label-row">
|
<div class="setting-label-row">
|
||||||
<span class="setting-label">{{ t('koreader.syncWithGrimmory') }}</span>
|
<span class="setting-label">{{ t('koreader.syncWithGrimmory') }}</span>
|
||||||
<p-toggle-switch
|
<p-toggle-switch
|
||||||
name="syncWithGrimmoryReader"
|
name="syncWithWebReader"
|
||||||
[(ngModel)]="syncWithGrimmoryReader"
|
[(ngModel)]="syncWithWebReader"
|
||||||
(ngModelChange)="onToggleSyncWithGrimmoryReader($event)"
|
(ngModelChange)="onToggleSyncWithWebReader($event)"
|
||||||
inputId="syncWithGrimmoryReader"
|
inputId="syncWithWebReader"
|
||||||
[disabled]="!credentialsSaved || !koReaderSyncEnabled">
|
[disabled]="!credentialsSaved || !koReaderSyncEnabled">
|
||||||
</p-toggle-switch>
|
</p-toggle-switch>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+5
-5
@@ -33,7 +33,7 @@ export class KoreaderSettingsComponent {
|
|||||||
editMode = true;
|
editMode = true;
|
||||||
showPassword = false;
|
showPassword = false;
|
||||||
koReaderSyncEnabled = false;
|
koReaderSyncEnabled = false;
|
||||||
syncWithGrimmoryReader = false;
|
syncWithWebReader = false;
|
||||||
koReaderUsername = '';
|
koReaderUsername = '';
|
||||||
koReaderPassword = '';
|
koReaderPassword = '';
|
||||||
credentialsSaved = false;
|
credentialsSaved = false;
|
||||||
@@ -70,7 +70,7 @@ export class KoreaderSettingsComponent {
|
|||||||
this.koReaderUsername = koreaderUser.username;
|
this.koReaderUsername = koreaderUser.username;
|
||||||
this.koReaderPassword = koreaderUser.password;
|
this.koReaderPassword = koreaderUser.password;
|
||||||
this.koReaderSyncEnabled = koreaderUser.syncEnabled;
|
this.koReaderSyncEnabled = koreaderUser.syncEnabled;
|
||||||
this.syncWithGrimmoryReader = koreaderUser.syncWithGrimmoryReader ?? koreaderUser.syncWithBookloreReader ?? false;
|
this.syncWithWebReader = koreaderUser.syncWithWebReader ?? false;
|
||||||
this.credentialsSaved = true;
|
this.credentialsSaved = true;
|
||||||
},
|
},
|
||||||
error: err => {
|
error: err => {
|
||||||
@@ -113,12 +113,12 @@ export class KoreaderSettingsComponent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onToggleSyncWithGrimmoryReader(enabled: boolean) {
|
onToggleSyncWithWebReader(enabled: boolean) {
|
||||||
this.koreaderService.toggleSyncProgressWithGrimmoryReader(enabled).pipe(
|
this.koreaderService.toggleSyncProgressWithWebReader(enabled).pipe(
|
||||||
takeUntilDestroyed(this.destroyRef)
|
takeUntilDestroyed(this.destroyRef)
|
||||||
).subscribe({
|
).subscribe({
|
||||||
next: () => {
|
next: () => {
|
||||||
this.syncWithGrimmoryReader = enabled;
|
this.syncWithWebReader = enabled;
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'success',
|
severity: 'success',
|
||||||
summary: this.t.translate('settingsDevice.koreader.syncUpdated'),
|
summary: this.t.translate('settingsDevice.koreader.syncUpdated'),
|
||||||
|
|||||||
+8
-13
@@ -69,14 +69,14 @@ describe('KoreaderService', () => {
|
|||||||
username: 'reader',
|
username: 'reader',
|
||||||
password: 'secret123',
|
password: 'secret123',
|
||||||
syncEnabled: false,
|
syncEnabled: false,
|
||||||
syncWithGrimmoryReader: true,
|
syncWithWebReader: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(responseBody).toEqual({
|
expect(responseBody).toEqual({
|
||||||
username: 'reader',
|
username: 'reader',
|
||||||
password: 'secret123',
|
password: 'secret123',
|
||||||
syncEnabled: false,
|
syncEnabled: false,
|
||||||
syncWithGrimmoryReader: true,
|
syncWithWebReader: true,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -91,24 +91,19 @@ describe('KoreaderService', () => {
|
|||||||
request.flush(null);
|
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;
|
let completed = false;
|
||||||
|
|
||||||
service.toggleSyncProgressWithGrimmoryReader(false).subscribe(() => {
|
service.toggleSyncProgressWithWebReader(false).subscribe(() => {
|
||||||
completed = true;
|
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')
|
req.method === 'PATCH' && req.url.endsWith('/api/v1/koreader-users/me/sync-progress-with-grimmory')
|
||||||
);
|
);
|
||||||
expect(grimmoryRequest.request.params.get('enabled')).toBe('false');
|
expect(request.request.params.get('enabled')).toBe('false');
|
||||||
grimmoryRequest.flush('missing route', {status: 404, statusText: 'Not Found'});
|
expect(request.request.body).toBeNull();
|
||||||
|
request.flush(null);
|
||||||
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(completed).toBe(true);
|
expect(completed).toBe(true);
|
||||||
});
|
});
|
||||||
|
|||||||
+3
-11
@@ -2,16 +2,13 @@ import {inject, Injectable} from '@angular/core';
|
|||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {API_CONFIG} from '../../../../../core/config/api-config';
|
import {API_CONFIG} from '../../../../../core/config/api-config';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {catchError} from 'rxjs/operators';
|
|
||||||
|
|
||||||
|
|
||||||
export interface KoreaderUser {
|
export interface KoreaderUser {
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
syncEnabled: boolean;
|
syncEnabled: boolean;
|
||||||
syncWithGrimmoryReader?: boolean;
|
syncWithWebReader?: boolean;
|
||||||
// TODO(grimmory-cleanup): Remove once the backend no longer returns the legacy Booklore KOReader sync field.
|
|
||||||
syncWithBookloreReader?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable({
|
@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, {
|
return this.http.patch<void>(`${this.url}/me/sync-progress-with-grimmory`, null, {
|
||||||
params: {enabled: enabled.toString()}
|
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