fix(storygraph): skip progress sync on read transition

Updating status to read on StoryGraph automatically logs the remaining page count. Sending a
subsequent progress update for the full book page count would create a duplicate journal entry,
inflating the logged page count. Skip the progress update when transitioning to the read status.

Closes #643
This commit is contained in:
neon
2026-07-11 17:06:49 +00:00
parent 568bf9dd6f
commit 89545e6c69
2 changed files with 12 additions and 1 deletions
@@ -312,6 +312,15 @@ describe('StorygraphSyncService', () => {
await expect(makeService().syncBook(1, 1)).resolves.toBe('synced'); await expect(makeService().syncBook(1, 1)).resolves.toBe('synced');
expect(mockMatchService.matchBook).toHaveBeenCalled(); expect(mockMatchService.matchBook).toHaveBeenCalled();
expect(mockClient.post).toHaveBeenCalledTimes(1);
expect(mockClient.post).toHaveBeenCalledWith(
1,
cookies,
expect.stringContaining('/update-status.js?book_id=abc-123&status=read'),
{},
'csrf-token',
);
expect(mockClient.post).not.toHaveBeenCalledWith(1, cookies, '/update-progress', expect.anything(), 'csrf-token');
}); });
it('skips unselected books when sync mode is selected-only', async () => { it('skips unselected books when sync mode is selected-only', async () => {
@@ -470,7 +470,9 @@ export class StorygraphSyncService {
try { try {
await this.updateStatus(userId, cookies, match.storygraphBookId, storygraphStatus); await this.updateStatus(userId, cookies, match.storygraphBookId, storygraphStatus);
if (book.progress != null) { // StoryGraph's read transition logs the remaining pages. A subsequent progress update
// would create another journal entry for the full page count.
if (book.progress != null && storygraphStatus !== STORYGRAPH_STATUS.READ) {
await this.updateProgress(userId, cookies, match.storygraphBookId, book.progress); await this.updateProgress(userId, cookies, match.storygraphBookId, book.progress);
} }