readest/apps/readest.koplugin/readest_asynchttp.lua
ivanovsergey93 915cd3bd43
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 / 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 / test_web_app (2) (push) Waiting to run
PR checks / test_extensions (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
fix(koreader): reliable progress sync with hardened auth and error handling (#6684)
* fix(koreader): improve reading progress sync

* docs(koreader): document progress sync behavior and limitations

* fix(koreader): harden sync auth, conflict handling, and error reporting

* fix(koreader): keep non-auth 403 reasons and report the failed library sync step

* fix(koreader): move backward on manual pull only to an exact position

A manual pull could jump back when the remote xpointer only resolved
after trimming to a parent node (a chapter start or /body), since a
parent orders before its children. Manual pulls still go backward to an
exact page or an xpointer that resolves untrimmed; a trimmed xpointer
only ever moves forward. Automatic pulls stay forward-only.

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

* i18n(koreader): translate sync error messages

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

* fix(koreader): report a pulled position whose chapter is missing

Trimming an unresolvable xpointer fell back to /body, which resolves in
any book, so a pull reported success for a position it could not use.
Stop trimming above /body so such positions count as unusable.

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

---------

Co-authored-by: Sergey Ivanov <sergejs.ivanovs@applyit.lv>
Co-authored-by: Huang Xin <chrox.huang@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 13:31:01 +02:00

46 lines
1.7 KiB
Lua

-- Shared by auth and sync: do not let a lost Turbo callback strand callers.
local UIManager = require("ui/uimanager")
local logger = require("logger")
return { call = function(args, req)
if not UIManager.looper then return end
req:finalize()
local result, completed
local timeout
local function finish(res)
if completed then return end
completed = true
if timeout then UIManager:unschedule(timeout) end
result = res or { code = 0, headers = { ["content-type"] = "application/json" },
body = '{"error":"Empty HTTP response"}' }
result.status = result.code
if coroutine.status(args.thread) == "suspended" then
local ok, err = coroutine.resume(args.thread)
if not ok then logger.err("ReadestSync: HTTP callback failed:", err) end
end
end
timeout = function()
finish({ code = 0, readest_timeout = true,
headers = { ["content-type"] = "application/json" },
body = '{"error":"timeout","msg":"HTTP request timed out"}' })
end
UIManager:scheduleIn(args.timeout or 25, timeout)
local ok, err = pcall(function()
require("httpclient"):new():request({
url = req.url,
method = req.method,
body = req.env.spore.payload,
on_headers = function(headers)
for header, value in pairs(req.headers) do
if type(header) == "string" then headers:add(header, value) end
end
end,
}, finish)
end)
if not ok then
if timeout then UIManager:unschedule(timeout) end
completed = true
error(err)
end
return coroutine.create(function() coroutine.yield(result) end)
end }