readest/apps
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
..
readest-app fix(sync): give HTML chapter files their own sync identity (#7321) 2026-11-04 13:25:49 +01:00
readest-calibre-plugin feat(calibre): add multi-language support (#6768) 2026-10-13 18:46:06 +02:00
readest-crosspoint-plugin feat(crosspoint): sync CrossPoint 2.0 clippings with Readest highlights (#7317) 2026-11-04 11:22:58 +01:00
readest.koplugin fix(sync): give HTML chapter files their own sync identity (#7321) 2026-11-04 13:25:49 +01:00