compat(sync): compatibility for kosync server implementations that do not return timestamp (#2422)

This commit is contained in:
Huang Xin
2025-11-09 21:42:07 +08:00
committed by GitHub
parent 4b6c7776f5
commit b075c46ba3
@@ -213,13 +213,16 @@ export const useKOSync = (bookKey: string) => {
setSyncState('checking');
const remoteProgress = await kosyncClient.getProgress(book);
if (!remoteProgress || !remoteProgress.progress || !remoteProgress.timestamp) {
if (!remoteProgress || !remoteProgress.progress) {
setSyncState('synced');
return;
}
const localTimestamp = bookData?.config?.updatedAt || book.updatedAt;
const remoteIsNewer = remoteProgress.timestamp * 1000 > localTimestamp;
const remoteTimestamp = remoteProgress.timestamp
? remoteProgress.timestamp * 1000
: Date.now();
const remoteIsNewer = remoteTimestamp > localTimestamp;
if (strategy === 'receive' || (strategy === 'silent' && remoteIsNewer)) {
applyRemoteProgress(book, bookDoc, remoteProgress);
setSyncState('synced');