feat(sync): add readest koplugin for progress sync, also implements #1729 (#1785)

This commit is contained in:
Huang Xin
2025-08-13 00:24:47 +08:00
committed by GitHub
parent 3698e6ca28
commit 0dfa8e96f5
11 changed files with 291 additions and 175 deletions
+14 -9
View File
@@ -96,23 +96,28 @@ function ReadestSyncClient:pullChanges(params, callback)
socketutil:reset_timeout()
end
function ReadestSyncClient:pushChanges(changes)
function ReadestSyncClient:pushChanges(changes, callback)
self.client:reset_middlewares()
self.client:enable("Format.JSON")
self.client:enable("ReadestHeaders", {})
self.client:enable("ReadestAuth", {})
socketutil:set_timeout(SYNC_TIMEOUTS[1], SYNC_TIMEOUTS[2])
local ok, res = pcall(function()
return self.client:pushChanges(changes or {})
local co = coroutine.create(function()
local ok, res = pcall(function()
return self.client:pushChanges(changes or {})
end)
if ok then
callback(res.status == 200, res.body)
else
logger.dbg("ReadestSyncClient:pushChanges failure:", res)
callback(false, res.body)
end
end)
self.client:enable("AsyncHTTP", {thread = co})
coroutine.resume(co)
if UIManager.looper then UIManager:setInputTimeout() end
socketutil:reset_timeout()
if ok then
return res.status == 200 or res.status == 201, res.body
else
logger.dbg("ReadestSyncClient:pushChanges failure:", res)
return false, res.body
end
end
return ReadestSyncClient