readest/apps/readest.koplugin
Huang Xin 2d75e0937b
fix(sync): give HTML chapter files their own sync identity (#7321)
* fix(sync): give HTML chapter files their own sync identity

Web-novel downloaders such as the legado and moon KOReader plugins save
each chapter as its own HTML file under the book's title and author. The
metadata hash, which syncs reading progress across devices, then matched
every chapter of the book, so opening a new chapter could pull the
previous chapter's position. #7231 does not cover this: a chapter opened
for the first time has no save of its own, so a sibling's newer position
still wins.

HTML files (.html, .htm, .xhtml, .xhtm, .mhtml, .mht) now salt the meta
hash with the base filename, as PDFs already do (#5411), in both the
KOReader plugin and the app. The app keeps the salted hash from import
and never recomputes it on a metadata refresh. Files already opened keep
their cached hash; chapters opened after the update get their own.

Verified:
- Tests that fail without the fix:
  - spec/syncconfig_spec.lua "gives per-chapter HTML files of one book
    distinct hashes": expected 'Sword Coming|Fenghuo Xizhuhou||0001',
    got the hash source without the filename.
  - import-metahash.test.ts "imports HTML chapters with identical
    metadata as separate books" (expected the salted hash, got the
    shared one) and "refreshBookMetadata preserves the salted metaHash
    for HTML" (expected 'salted-import-hash', got the recomputed hash).
- All koplugin busted specs pass (513), luajit syntax check clean; the
  related app suites pass (34 files); pnpm lint and format:check clean.
- On a Kindle with KOReader, two HTML files sharing a title got the same
  meta_hash_v1 under the old plugin and distinct ones under the fix,
  each equal to md5 of "<title>|||<basename>".
- Not run: the cross-device sync round trip, because sync from that
  Kindle currently fails for an unrelated reason.

Closes #7313
Reported by zzzh3ng on GitHub

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(sync): salt the HTML metaHash when an existing row has none

An existing HTML row with no metaHash (imported before metaHashes
existed) kept undefined on re-import instead of getting a salted hash.
Keep the stored hash only when there is one.

Verified: the new import-metahash test "salts the metaHash when
re-importing an HTML book that has none" fails without this change
(expected undefined to be the salted hash) and passes with it; related
suites pass (35 files, 543 tests); pnpm lint and format:check clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:25:49 +01:00
..
docs fix(koreader): reliable progress sync with hardened auth and error handling (#6684) 2026-10-09 13:31:01 +02:00
icons feat(koplugin): Readest Library view in KOReader (#4056) 2026-05-04 23:12:34 +02:00
library fix(koplugin): collect sync workers before KOReader exits (#7293) 2026-11-03 16:41:51 +01:00
locales feat(koplugin): sign in with a QR code; fix the logged-out label and global logout (#7186) (#7192) 2026-11-01 04:01:53 +01:00
native/localsend-bin fix(deps): resolve open Dependabot alerts (#6813) 2026-10-15 07:59:43 +02:00
scripts test(kosync): check both xpointer forms against crengine at two DOM versions (#7178) 2026-10-31 10:02:43 +01:00
spec fix(sync): give HTML chapter files their own sync identity (#7321) 2026-11-04 13:25:49 +01:00
.busted feat(koplugin): Readest Library view in KOReader (#4056) 2026-05-04 23:12:34 +02:00
_meta.lua fix(kosync): add namespace to koreader plugin modules to avoid collision (#4153) 2026-05-14 08:56:36 +08:00
main.lua fix(koplugin): wait for Wi-Fi before pulling on wake (#7215) 2026-11-01 15:40:55 +01:00
readest-sync-api.json feat(koplugin): sign in with a QR code; fix the logged-out label and global logout (#7186) (#7192) 2026-11-01 04:01:53 +01:00
readest_asynchttp.lua fix(koreader): reliable progress sync with hardened auth and error handling (#6684) 2026-10-09 13:31:01 +02:00
readest_i18n.lua fix(kosync): add namespace to koreader plugin modules to avoid collision (#4153) 2026-05-14 08:56:36 +08:00
readest_localsend.lua fix(koplugin): stop BookDrop start errors popping up on every launch (#6604) 2026-10-03 14:55:58 +02:00
readest_selfupdate.lua fix(koplugin): extract self-update with ffi/archiver on KOReader 2026.07+ (#5656) 2026-08-12 19:02:20 +02:00
readest_sporeresponse.lua fix(koreader): reliable progress sync with hardened auth and error handling (#6684) 2026-10-09 13:31:01 +02:00
readest_supabaseauth.lua feat(koplugin): sign in with a QR code; fix the logged-out label and global logout (#7186) (#7192) 2026-11-01 04:01:53 +01:00
readest_syncannotations.lua fix(koreader): reliable progress sync with hardened auth and error handling (#6684) 2026-10-09 13:31:01 +02:00
readest_syncauth.lua feat(koplugin): sign in with a QR code; fix the logged-out label and global logout (#7186) (#7192) 2026-11-01 04:01:53 +01:00
readest_syncclient.lua fix(koplugin): collect sync workers before KOReader exits (#7293) 2026-11-03 16:41:51 +01:00
readest_syncconfig.lua fix(sync): give HTML chapter files their own sync identity (#7321) 2026-11-04 13:25:49 +01:00
readest_syncerror.lua fix(koreader): reliable progress sync with hardened auth and error handling (#6684) 2026-10-09 13:31:01 +02:00
readest_syncstats.lua fix(koreader): reliable progress sync with hardened auth and error handling (#6684) 2026-10-09 13:31:01 +02:00
readest_synctime.lua fix(koreader): reliable progress sync with hardened auth and error handling (#6684) 2026-10-09 13:31:01 +02:00
supabase-auth-api.json feat(koplugin): sign in with a QR code; fix the logged-out label and global logout (#7186) (#7192) 2026-11-01 04:01:53 +01:00