♻️ 书源 id 去掉 ext. 前缀,沿用旧内置源数据
Co-authored-by: Copilot <[email protected]>
This commit is contained in:
1 parent
01e572a5ee
commit
f8ad3f73a6
29 files changed
+173
-173
No files matched your search
@@ -188,7 +188,7 @@ end)
|
||||
package.loaded["moonsource_weread.source"] = nil
|
||||
local WeChat = require("moonsource_weread.source")
|
||||
|
||||
local REF = { source_id = "ext.weread", stable_id = "b1", book = { title = "微信书" } }
|
||||
local REF = { source_id = "weread", stable_id = "b1", book = { title = "微信书" } }
|
||||
|
||||
do
|
||||
local caps = WeChat.new():capabilities()
|
||||
@@ -254,7 +254,7 @@ do
|
||||
local StatsDB = require("book.stats_db")
|
||||
local real_book_totals = StatsDB.bookTotals
|
||||
StatsDB.bookTotals = function(source_id)
|
||||
Assert.eq(source_id, "ext.weread")
|
||||
Assert.eq(source_id, "weread")
|
||||
return { same = 500, broken = 90 }
|
||||
end
|
||||
local result
|
||||
@@ -396,7 +396,7 @@ do
|
||||
local Session = require("reader.session")
|
||||
local orig_current = Session.current
|
||||
Session.current = function()
|
||||
return { identity = { source_id = "ext.weread", stable_id = "bp" } }
|
||||
return { identity = { source_id = "weread", stable_id = "bp" } }
|
||||
end
|
||||
ProgressDB.get = orig_get
|
||||
posted = {}
|
||||
@@ -430,7 +430,7 @@ do
|
||||
stub("book.stats", function()
|
||||
return { push = function(source) stats_pushes[#stats_pushes + 1] = source end }
|
||||
end)
|
||||
local identity = { source_id = "ext.weread", stable_id = "bp", chapter_idx = 1 }
|
||||
local identity = { source_id = "weread", stable_id = "bp", chapter_idx = 1 }
|
||||
src:onEvent("chapter_changed", {
|
||||
identity = identity,
|
||||
position = { fraction = 0.1, chapter_idx = 1, chapter_fraction = 0.2 },
|
||||
@@ -489,7 +489,7 @@ do
|
||||
cb({ book = { chapterUid = 33, chapterIdx = 9, chapterOffset = 120, progress = 40 } })
|
||||
return { cancel = function() end }
|
||||
end
|
||||
local identity = { source_id = "ext.weread", stable_id = "bp", chapter_idx = 1 }
|
||||
local identity = { source_id = "weread", stable_id = "bp", chapter_idx = 1 }
|
||||
|
||||
Position.loadAsync = function(_identity, _chapter, cb) cb(nil, "offline") end
|
||||
local pos, err
|
||||
@@ -670,7 +670,7 @@ do
|
||||
BookDB.get = function()
|
||||
return { meta = {
|
||||
weread_ended = true,
|
||||
source = { ["ext.weread"] = { pay_type = 2, ended = false } },
|
||||
source = { ["weread"] = { pay_type = 2, ended = false } },
|
||||
} }
|
||||
end
|
||||
Assert.is_true(put({ fraction = 1, extra = UID }))
|
||||
@@ -750,7 +750,7 @@ do
|
||||
Assert.is_nil(map_err)
|
||||
Assert.eq(captured.chapter_offset, 0, "对不上且没有可用比例/偏移时按章首上报")
|
||||
toc_payload["b1"] = nil
|
||||
require("book.toc_db").removeIdentity("ext.weread", "b1")
|
||||
require("book.toc_db").removeIdentity("weread", "b1")
|
||||
require("moonsource_weread.toc").clear()
|
||||
StatsDB.unsyncedBySource, StatsDB.markSynced = orig_unsynced, orig_mark
|
||||
end
|
||||
@@ -874,7 +874,7 @@ do
|
||||
Assert.not_nil(result)
|
||||
|
||||
-- 合法 http(s) 封面入缓存,coverRequest 带回会话头
|
||||
local req = src:coverRequest({ source_id = "ext.weread", stable_id = "b1" })
|
||||
local req = src:coverRequest({ source_id = "weread", stable_id = "b1" })
|
||||
Assert.not_nil(req)
|
||||
Assert.eq(req.url, "https://cdn.example.com/a.jpg")
|
||||
Assert.eq(req.headers.Cookie, "wr_skey=stub")
|
||||
@@ -882,18 +882,18 @@ do
|
||||
-- 新源实例没有内存缓存,必须从 Book/数据库恢复封面。
|
||||
local fresh = WeChat.new()
|
||||
local direct = fresh:coverRequest({
|
||||
source_id = "ext.weread", stable_id = "b1", cover = "https://cdn.example.com/a.jpg",
|
||||
source_id = "weread", stable_id = "b1", cover = "https://cdn.example.com/a.jpg",
|
||||
})
|
||||
Assert.eq(direct.url, "https://cdn.example.com/a.jpg")
|
||||
Assert.eq(direct.headers.Cookie, "wr_skey=stub")
|
||||
|
||||
-- 非 http(s) 前缀的封面不入缓存
|
||||
local req2, err2 = src:coverRequest({ source_id = "ext.weread", stable_id = "b2" })
|
||||
local req2, err2 = src:coverRequest({ source_id = "weread", stable_id = "b2" })
|
||||
Assert.is_nil(req2)
|
||||
Assert.eq(err2, "无封面")
|
||||
|
||||
-- 无封面字段的书籍
|
||||
local req3 = src:coverRequest({ source_id = "ext.weread", stable_id = "b3" })
|
||||
local req3 = src:coverRequest({ source_id = "weread", stable_id = "b3" })
|
||||
Assert.is_nil(req3)
|
||||
|
||||
-- 重复列表刷新封面缓存(后写覆盖先写)
|
||||
@@ -907,12 +907,12 @@ do
|
||||
end
|
||||
src:syncBooksAsync(nil, function() end)
|
||||
require("support.stubs").flush()
|
||||
Assert.eq(src:coverRequest({ source_id = "ext.weread", stable_id = "b1" }).url,
|
||||
Assert.eq(src:coverRequest({ source_id = "weread", stable_id = "b1" }).url,
|
||||
"https://cdn.example.com/a2.jpg")
|
||||
|
||||
-- close 清空实例的封面缓存
|
||||
src:close()
|
||||
local req4 = src:coverRequest({ source_id = "ext.weread", stable_id = "b1" })
|
||||
local req4 = src:coverRequest({ source_id = "weread", stable_id = "b1" })
|
||||
Assert.is_nil(req4)
|
||||
end
|
||||
|
||||
@@ -971,14 +971,14 @@ do
|
||||
end
|
||||
local annotations
|
||||
WeChat.new():pullNotesAsync({
|
||||
source_id = "ext.weread", stable_id = "bpull", chapter_idx = 5,
|
||||
source_id = "weread", stable_id = "bpull", chapter_idx = 5,
|
||||
}, function(value) annotations = value end)
|
||||
require("support.stubs").flush()
|
||||
Assert.eq(annotations[1].chapter_idx, 5)
|
||||
|
||||
-- 目录缓存没有、也拉不到:章节号留空,绝不回退成原始序号 6(本地第 6 章是别的章)。
|
||||
toc_payload["bpull"] = nil
|
||||
require("book.toc_db").removeIdentity("ext.weread", "bpull")
|
||||
require("book.toc_db").removeIdentity("weread", "bpull")
|
||||
require("source.toc").clear()
|
||||
fake_client.chapterInfosAsync = function(_, _, cb)
|
||||
cb(nil, "目录拉取失败")
|
||||
@@ -986,7 +986,7 @@ do
|
||||
end
|
||||
annotations = nil
|
||||
WeChat.new():pullNotesAsync({
|
||||
source_id = "ext.weread", stable_id = "bpull", chapter_idx = 5,
|
||||
source_id = "weread", stable_id = "bpull", chapter_idx = 5,
|
||||
}, function(value) annotations = value end)
|
||||
require("support.stubs").flush()
|
||||
Assert.len(annotations, 1)
|
||||
@@ -997,7 +997,7 @@ end
|
||||
do
|
||||
chapter_fetches = 0
|
||||
local NOTE_REF = {
|
||||
source_id = "ext.weread",
|
||||
source_id = "weread",
|
||||
stable_id = "bpush",
|
||||
chapter_idx = 2,
|
||||
book = { title = "微信书" },
|
||||
@@ -1015,10 +1015,10 @@ do
|
||||
chapter_range_html = "<p>旧划线</p><p>新划线</p><p>补偿划线</p>"
|
||||
.. "<p>部分一</p><p>部分二</p>"
|
||||
local Paths = require("utils.paths")
|
||||
local chapter_path = Paths.chapterPath("bpush", 2, "ext.weread")
|
||||
assert(Paths.ensureDir(Paths.bookWorkDir("bpush", "ext.weread")))
|
||||
local chapter_path = Paths.chapterPath("bpush", 2, "weread")
|
||||
assert(Paths.ensureDir(Paths.bookWorkDir("bpush", "weread")))
|
||||
-- 沙箱跨运行保留:清掉上次留下的 range 原文缓存,首个定位必走一次拉取并回填缓存
|
||||
os.remove(Paths.bookWorkDir("bpush", "ext.weread") .. "/2.position.json")
|
||||
os.remove(Paths.bookWorkDir("bpush", "weread") .. "/2.position.json")
|
||||
local chapter_file = assert(io.open(chapter_path, "wb"))
|
||||
chapter_file:write("<html><body><h1>微信书</h1><p>旧划线</p><p>新划线</p>"
|
||||
.. "<p>补偿划线</p><p>部分一</p><p>部分二</p></body></html>")
|
||||
@@ -1293,13 +1293,13 @@ do
|
||||
package.loaded["workers.tasks"] = { enqueue = function(spec) enqueued[#enqueued + 1] = spec.key; return spec end }
|
||||
local src = WeChat.new()
|
||||
local ok
|
||||
src:deleteBookAsync({ source_id = "ext.weread", stable_id = "del1" }, function(success)
|
||||
src:deleteBookAsync({ source_id = "weread", stable_id = "del1" }, function(success)
|
||||
ok = success
|
||||
end)
|
||||
require("support.stubs").flush()
|
||||
Assert.is_true(ok)
|
||||
Assert.eq(remembered_stats_books.marked_deleted.stable_id, "del1")
|
||||
Assert.eq(enqueued[1], "dirty\0ext.weread")
|
||||
Assert.eq(enqueued[1], "dirty\0weread")
|
||||
src:syncBooksAsync({ dirty_only = true }, function() end)
|
||||
require("support.stubs").flush()
|
||||
Assert.eq(removed, "del1")
|
||||
@@ -1312,7 +1312,7 @@ end
|
||||
-- 段评:开关读源配置;按目录解析本章 chapter_uid,章节 HTML 读本地文件定位。
|
||||
do
|
||||
toc_payload["b1"] = [[ [{"idx":1,"source_idx":2,"uid":"40"}] ]]
|
||||
require("book.toc_db").removeIdentity("ext.weread", "b1")
|
||||
require("book.toc_db").removeIdentity("weread", "b1")
|
||||
local Settings = require("utils.settings")
|
||||
local src = WeChat.new()
|
||||
Assert.is_false(src:paragraphReviewsEnabled())
|
||||
@@ -1365,7 +1365,7 @@ do
|
||||
Assert.not_nil(err)
|
||||
Assert.len(calls, 3)
|
||||
toc_payload["b1"] = nil
|
||||
require("book.toc_db").removeIdentity("ext.weread", "b1")
|
||||
require("book.toc_db").removeIdentity("weread", "b1")
|
||||
require("moonsource_weread.toc").clear()
|
||||
|
||||
-- 书名搜索:只留带 bookId 的书目。
|
||||
@@ -1402,7 +1402,7 @@ do
|
||||
local src = WeChat.new()
|
||||
local called = false
|
||||
local job = src:pushNotesAsync(
|
||||
{ source_id = "ext.weread", stable_id = "bcancel", chapter_idx = 1 },
|
||||
{ source_id = "weread", stable_id = "bcancel", chapter_idx = 1 },
|
||||
{ { drawer = "lighten", text = "甲" } },
|
||||
function() called = true end
|
||||
)
|
||||
@@ -1417,13 +1417,13 @@ do
|
||||
|
||||
-- 无事可做直接成功,不发请求。
|
||||
local ok
|
||||
Assert.is_nil(src:pushNotesAsync({ source_id = "ext.weread", stable_id = "bcancel", chapter_idx = 1 },
|
||||
Assert.is_nil(src:pushNotesAsync({ source_id = "weread", stable_id = "bcancel", chapter_idx = 1 },
|
||||
{ { drawer = "lighten", text = "甲", wr_bookmark_id = "b", wr_range = "0-1" } },
|
||||
function(v) ok = v end))
|
||||
Assert.is_true(ok)
|
||||
Assert.eq(requests, 1)
|
||||
toc_payload["bcancel"] = nil
|
||||
require("book.toc_db").removeIdentity("ext.weread", "bcancel")
|
||||
require("book.toc_db").removeIdentity("weread", "bcancel")
|
||||
fake_client.bookmarkListAsync = nil
|
||||
fake_client.myReviewsAsync = nil
|
||||
end
|
||||
@@ -1433,9 +1433,9 @@ do
|
||||
remembered_stats_books.local_library = { "a", "b", "gone" }
|
||||
remembered_stats_books.pending_adds = {}
|
||||
remembered_stats_books.local_rows = {
|
||||
a = { source_id = "ext.weread", stable_id = "a", title = "甲", deleted = 0 },
|
||||
b = { source_id = "ext.weread", stable_id = "b", title = "乙旧", category = "我的分组", deleted = 0 },
|
||||
gone = { source_id = "ext.weread", stable_id = "gone", title = "删", deleted = 0 },
|
||||
a = { source_id = "weread", stable_id = "a", title = "甲", deleted = 0 },
|
||||
b = { source_id = "weread", stable_id = "b", title = "乙旧", category = "我的分组", deleted = 0 },
|
||||
gone = { source_id = "weread", stable_id = "gone", title = "删", deleted = 0 },
|
||||
}
|
||||
local ids_req, books_req, full_called = nil, nil, false
|
||||
fake_client.shelfSyncIdsAsync = function(_, synckey, count, cb)
|
||||
@@ -1564,7 +1564,7 @@ do
|
||||
remembered_stats_books.local_library = { "a" }
|
||||
remembered_stats_books.pending_adds = {}
|
||||
remembered_stats_books.local_rows = {
|
||||
a = { source_id = "ext.weread", stable_id = "a", title = "甲", deleted = 0 },
|
||||
a = { source_id = "weread", stable_id = "a", title = "甲", deleted = 0 },
|
||||
}
|
||||
local full_called = false
|
||||
fake_client.shelfSyncIdsAsync = function(_, _synckey, _count, cb)
|
||||
@@ -1664,7 +1664,7 @@ do
|
||||
local old_is_connected = Network.isConnected
|
||||
local connected = true
|
||||
local active = {
|
||||
identity = { source_id = "ext.weread", stable_id = "page-sync" },
|
||||
identity = { source_id = "weread", stable_id = "page-sync" },
|
||||
}
|
||||
local saves, scheduled, ticks, sync_callbacks = 0, {}, {}, {}
|
||||
local cancelled = 0
|
||||
@@ -1756,7 +1756,7 @@ do
|
||||
local old_uid, old_source_index = Toc.uid, Toc.sourceIndex
|
||||
local old_report = fake_client.reportReadAsync
|
||||
local active = {
|
||||
identity = { source_id = "ext.weread", stable_id = "presence" },
|
||||
identity = { source_id = "weread", stable_id = "presence" },
|
||||
}
|
||||
local scheduled, sent = {}, {}
|
||||
Session.current = function() return active end
|
||||
|
||||
Reference in new issue
Block a user