mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 08:21:39 -06:00
cc50b55eeb
Add original and text-only EPUB delivery choices across Kobo, KOReader, OPDS, web downloads and email while keeping source files unchanged. Persist server defaults, device overrides and captured artifact identities so retries and guided replacement retain the selected rendition. Preserve saved progress across first opens, replacement resets and stale updates, and project annotations against the copy delivered to each device. Handle XML resource references, large inodes, retry backoff and background worker state correctly. Consolidate the schema changes into one migration and retain released-client request and response compatibility. Verify with the full server and client checks, delivery and sync HTTP suites, independent code reviews, and live KOReader download/settings/reader proof. Fixes #1496 Closes #1603 Closes #1714 Fixes #1723 Ref #1633 Ref #1508 Ref #1621 Ref #1136
40 lines
1.4 KiB
Lua
40 lines
1.4 KiB
Lua
--[[--
|
|
Socket and size budgets for a single file transfer.
|
|
|
|
Book files outgrow KOReader's inherited file-transfer budget: a 60 second total
|
|
socket timeout caps a transfer at whatever an e-reader can move in a minute, so
|
|
a large book fails on a slow link even while it is making steady progress. The
|
|
block timeout is the stall detector instead, bounding the gap between
|
|
successful socket operations, and the total ceiling scales with the size the
|
|
server recorded for the file.
|
|
]]
|
|
|
|
local STALL_TIMEOUT = 30
|
|
local BASE_TIMEOUT = 120
|
|
local MIN_BYTES_PER_SECOND = 8 * 1024
|
|
local MAX_TIMEOUT = 6 * 60 * 60
|
|
|
|
-- Ceiling for a transfer whose size the server did not record.
|
|
local MAX_TRANSFER_BYTES = 512 * 1024 * 1024
|
|
-- Servers may add container overhead, so the recorded size is a margin rather
|
|
-- than an exact ceiling.
|
|
local SIZE_MARGIN = 1.25
|
|
local SIZE_SLACK_BYTES = 1024 * 1024
|
|
|
|
local TransferPolicy = {}
|
|
|
|
TransferPolicy.MAX_TRANSFER_BYTES = MAX_TRANSFER_BYTES
|
|
|
|
function TransferPolicy.timeouts(expected_bytes)
|
|
local size = math.max(0, tonumber(expected_bytes) or 0)
|
|
return STALL_TIMEOUT, math.min(BASE_TIMEOUT + math.ceil(size / MIN_BYTES_PER_SECOND), MAX_TIMEOUT)
|
|
end
|
|
|
|
function TransferPolicy.maxBytes(expected_bytes)
|
|
local size = tonumber(expected_bytes)
|
|
if not size or size <= 0 then return MAX_TRANSFER_BYTES end
|
|
return math.min(8 * 1024 * 1024 * 1024, math.ceil(size * SIZE_MARGIN) + SIZE_SLACK_BYTES)
|
|
end
|
|
|
|
return TransferPolicy
|