✨ 初始提交:月读第三方书源插件集合
每个书源一个独立插件目录,含微信读书公众号订阅、书架导入等完整功能。 Co-authored-by: Copilot <[email protected]>
This commit is contained in:
commit
0907702861
27 files changed
+18687
No files matched your search
@@ -0,0 +1,58 @@
|
||||
--[[--
|
||||
进度编排保护同步取消句柄与目录返回前的账号变更。
|
||||
|
||||
@module tests.moonsource_xiaoxiang.progress_spec
|
||||
--]]
|
||||
---@diagnostic disable: undefined-field, missing-fields, param-type-mismatch
|
||||
|
||||
local A = require("support.assert")
|
||||
local cookie, delayed, toc_cb, write_cb, stopped, writes = "old", false, nil, nil, false, 0
|
||||
local toc = { { uid = "77", title = "第一章" }, { uid = "78", title = "第二章" } }
|
||||
package.loaded["moonsource_xiaoxiang.client"] = {
|
||||
cookie = function() return cookie end,
|
||||
shelfAsync = function(cb)
|
||||
cb({ { bookid = "123", ccid = "78" } })
|
||||
return { cancel = function() end }
|
||||
end,
|
||||
progressAsync = function(_book, _chapter, cb)
|
||||
writes = writes + 1
|
||||
write_cb = cb
|
||||
return { cancel = function() stopped = true end }
|
||||
end,
|
||||
}
|
||||
package.loaded["source.toc"] = { index = function() return 2 end }
|
||||
package.loaded["moonsource_xiaoxiang.source"] = nil
|
||||
local source = require("moonsource_xiaoxiang.source").new()
|
||||
function source:loadTocAsync(_identity, cb)
|
||||
toc_cb = cb
|
||||
if not delayed then cb(toc) end
|
||||
return { cancel = function() stopped = true end }
|
||||
end
|
||||
local identity = { source_id = "ext.xiaoxiang", stable_id = "123" }
|
||||
local result, err
|
||||
source:getProgressAsync(identity, function(data) result = data end)
|
||||
A.eq(result.chapter_idx, 2)
|
||||
A.eq(result.fraction, 0.5)
|
||||
delayed, stopped, result = true, false, nil
|
||||
local handle = source:getProgressAsync(identity, function(data) result = data end)
|
||||
handle.cancel()
|
||||
A.is_true(stopped)
|
||||
toc_cb(toc)
|
||||
A.is_nil(result)
|
||||
source:getProgressAsync(identity, function(data, reason) result, err = data, reason end)
|
||||
cookie = "new"
|
||||
toc_cb(toc)
|
||||
A.is_nil(result)
|
||||
A.eq(err, "账号已变化,请重新登录")
|
||||
cookie, delayed, stopped = "old", false, false
|
||||
handle = source:putProgressAsync(identity, { chapter_idx = 2 }, function(data) result = data end)
|
||||
handle.cancel()
|
||||
A.is_true(stopped)
|
||||
write_cb({})
|
||||
A.is_nil(result)
|
||||
delayed = true
|
||||
source:putProgressAsync(identity, { chapter_idx = 2 }, function(data, reason) result, err = data, reason end)
|
||||
cookie = "new"
|
||||
toc_cb(toc)
|
||||
A.eq(writes, 1, "不能把旧书进度推到新账号")
|
||||
A.eq(err, "账号已变化,请重新登录")
|
||||
Reference in new issue
Block a user