readest/apps/readest.koplugin/readest-sync-api.json
Huang Xin 314a62d117
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
feat(koplugin): sign in with a QR code; fix the logged-out label and global logout (#7186) (#7192)
* feat(koplugin): sign in to Readest with a QR code (#7186)

Readest > Log in Readest Account now offers "Sign in with a code", the
device-code flow the CrossPoint plugin uses. KOReader shows a QR code,
the /link URL and a code. A phone signed in to Readest scans it and
approves the code on /link, and KOReader receives an ordinary Readest
session that refreshes as a password login does. Nothing is typed on
the e-reader, and accounts that sign in with Google or Apple, which
have no password, can now use the plugin.

- /api/crosspoint/device/token: with grant "session", an approved code
  returns the user's Supabase session instead of a CrossPoint key. The
  session comes from an admin magic link verified on the server; the
  link is never sent. If the session can't be started, the approval is
  put back for the next poll, as for keys.
- Plugin: requestDeviceCode/pollDeviceToken in the sync API spec.
  Polling stops on approval, on expiry, or when the code message is
  dismissed. A network failure keeps it polling. The new session is
  written to disk at once, like a refreshed one.
- /link says "Link a Reader", since KOReader uses it too.

Verified:
- crosspoint-routes.test.ts "signs KOReader in with a session of its
  own once the code is approved" fails on main (expected 500 to be
  200) and passes. syncauth_spec.lua "SyncAuth:loginWithCode" (4 specs)
  covers approval, expiry, network failure and dismissal.
- pnpm test: 1215 files, 14467 tests passed. pnpm lint: clean (tsc,
  Biome). pnpm test:lua: 495 successes. pnpm lint:lua: clean.
- Kindle (KOReader), plugin built from this branch against a local
  dev server: Log in > Sign in with a code showed the QR code and code.
  The code was approved on web.readest.com/link, the next poll returned
  200, the menu read "Log out as <user>", and opening Readest library
  synced (runCloudSync[both] done: success=true, 90 books pulled).
  After restarting KOReader it was still signed in.
- The e2e run found two bugs, fixed here: the closed menu was refreshed
  after sign-in and came back under the next tap (it toggled Auto
  sync), and the session was lost on an exit that skipped saving.
- Not run: Android KOReader, and the production host (the QR there
  encodes web.readest.com/link?code=…; the dev server's encoded
  0.0.0.0:3010).

Reported by misc-tw on GitHub.

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

* fix(koplugin): keep showing the account while a refresh token can renew the session (#7186)

Tools > Readest offered "Log in Readest Account" as soon as the access
token expired, although the saved refresh token renews it on the next
sync. A night in standby outlasts the token, so the plugin looked
logged out every morning and the menu asked for the password again.
needsLogin now asks for a login only while authentication is paused or
no refresh token is saved.

Verified:
- New spec "SyncAuth:needsLogin stays signed in when only the access
  token expired (#7186)" fails on main (needsLogin returned true for a
  token expired 8 h ago) and passes with the fix.
- pnpm test:lua: 493 successes, 0 failures. pnpm lint:lua: clean.
- Kindle (KOReader, plugin 0.12.16) with an access token expired 8.5
  days earlier and its refresh token saved: Tools > Readest showed
  "Log in Readest Account". With the fixed readest_syncauth.lua pushed
  and KOReader restarted, it showed "Log out as <user>"; Pull stats now
  then renewed the token (expires_at moved to now + 60457 s) with no
  login.
- Not run: the reporter's BOOX Go 7 Color (Android).

Reported by misc-tw on GitHub.

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

* fix(koplugin): log out only this device, like the Readest app

Readest > Log out called Supabase /logout without a scope. Supabase's
default scope is global, so logging out of KOReader also ended every
other session of the account (app, web, other readers) at their next
token refresh. The app signs out with scope "local" (#6709); the plugin
now sends the same.

Verified:
- New spec "SupabaseAuthClient:sign_out signs out only this device"
  fails on main (no params sent; expected { scope = "local" }) and
  passes with the fix.
- The request KOReader's Spore library builds from the spec:
  main  POST .../auth/v1/logout
  fix   POST .../auth/v1/logout?scope=local
- Kindle (KOReader): signed in, opened a second session of the same
  account from a shell, then Log out in the plugin. The menu went back
  to "Log in Readest Account" and the second session still refreshed
  (HTTP 200); it was then signed out with scope=local.
- pnpm test:lua: 492 successes, 0 failures. pnpm lint:lua: clean.
- Not run: the global-scope logout on main against a live account, to
  avoid signing the account out everywhere.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 04:01:53 +01:00

64 lines
1.9 KiB
JSON

{
"base_url": "https://web.readest.com/api",
"name": "readest-sync-api",
"methods": {
"pullChanges": {
"path": "/sync",
"method": "GET",
"required_params": ["since", "type", "book", "meta_hash"],
"optional_params": ["limit"],
"expected_status": [200, 400, 301, 401, 403]
},
"pushChanges": {
"path": "/sync",
"method": "POST",
"required_params": ["books", "notes", "configs"],
"optional_params": ["statBooks", "statPages"],
"payload": ["books", "notes", "configs", "statBooks", "statPages"],
"expected_status": [200, 201, 301, 400, 401, 403]
},
"pullBooks": {
"path": "/sync?type=books",
"method": "GET",
"required_params": ["since"],
"expected_status": [200, 400, 301, 401, 403]
},
"getDownloadUrl": {
"path": "/storage/download",
"method": "GET",
"required_params": ["fileKey"],
"expected_status": [200, 400, 301, 401, 403, 404]
},
"listFiles": {
"path": "/storage/list",
"method": "GET",
"required_params": ["bookHash"],
"expected_status": [200, 400, 301, 401, 403]
},
"deleteFile": {
"path": "/storage/delete",
"method": "DELETE",
"required_params": ["fileKey"],
"expected_status": [200, 400, 301, 401, 403, 404]
},
"getUploadUrl": {
"path": "/storage/upload",
"method": "POST",
"required_params": ["fileName", "fileSize", "bookHash"],
"payload": ["fileName", "fileSize", "bookHash"],
"expected_status": [200, 400, 301, 401, 403]
},
"requestDeviceCode": {
"path": "/crosspoint/device/code",
"method": "POST",
"expected_status": [200, 500]
},
"pollDeviceToken": {
"path": "/crosspoint/device/token",
"method": "POST",
"required_params": ["device_code", "grant"],
"payload": ["device_code", "grant"],
"expected_status": [200, 400, 500]
}
}
}