readest/docker/volumes/db/migrations/025_crosspoint_documents.sql
Huang Xin 9703d46113
feat(crosspoint): plugin updates, version display, and sync for optimized EPUBs (#6592)
* feat(crosspoint): check for plugin updates from the web settings card

The Readest card on CrossPoint's web Settings page shows the installed
plugin version and a Check for update button. Like the KOReader plugin,
it reads latest.json from download.readest.com through the device relay.
Update streams the release zip to the SD card, unpacks it with the JSZip
the device already serves, and writes each file into the plugin's folder,
manifest.json last, so an update cut short is offered again.

CrossPoint never shows a plugin's version on the reader, so the release
job now stamps it at the start of device.json's description, which the
reader's plugin list shows under Readest. The committed manifest version
becomes 0.0.1, so a copy made from the repo is offered the release.

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

* feat(crosspoint): keep syncing books rewritten by Optimize EPUB

CrossPoint's File Manager can optimize an EPUB on upload. That rewrites
the file, so its KOReader partial MD5 no longer matches the Readest book,
and progress sync and reading statistics lost track of it.

Sign-in now turns on KOReader Sync's Send metadata, so progress uploads
carry the book's title and authors. An upload under an unknown document
id links it to the one library EPUB with that title (the first author
breaks ties), stored in the new crosspoint_documents table (migration
025), without moving Readest's position back on that first upload.
Progress reads, progress uploads and reading sessions then follow the
link.

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

* fix(crosspoint): fail instead of syncing a copy under its own id on a database error

A failed link lookup, library query or link write counted as "not
linked", so a linked copy's reading session was recorded under the
copy's own hash, a progress read answered 404, and a progress upload
was saved under the copy's hash and acknowledged. The link helpers now
report the error like a query, and the routes answer 500 so the reader
retries.

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

* fix(crosspoint): compare every library book with a copy's title

The title lookup stopped at 20 rows in no particular order, so with more
books sharing a title it could miss Readest's own file or a second book
that fits, and link a copy it should have left alone.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 13:37:10 +02:00

15 lines
891 B
SQL

-- Copies of Readest books on CrossPoint readers that hash differently from the
-- book: CrossPoint's "Optimize EPUB" upload rewrites the file, so the KOSync
-- document id (the file's partial MD5) matches no book_hash. The first progress
-- upload links the copy to the library book by title and author; later syncs
-- follow the link. Only the service role reads or writes it.
CREATE TABLE IF NOT EXISTS public.crosspoint_documents (
user_id uuid NOT NULL REFERENCES auth.users (id) ON DELETE CASCADE,
document text NOT NULL, -- partial MD5 of the file on the reader
book_hash text NOT NULL, -- the library book it is a copy of
created_at timestamp with time zone NOT NULL DEFAULT now(),
PRIMARY KEY (user_id, document)
);
ALTER TABLE public.crosspoint_documents ENABLE ROW LEVEL SECURITY;
REVOKE ALL ON public.crosspoint_documents FROM PUBLIC, anon, authenticated;