♻️ 书源 id 去掉 ext. 前缀,沿用旧内置源数据

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
GarfieldandCopilot committed 2026-11-16 14:07:45 +08:00
1 parent 818a3d9067
commit a8ce4da366
13 files changed
+42 -42

No files matched your search

@@ -7,7 +7,7 @@
local _ = require("l10n").get("moonsource_jdread") local _ = require("l10n").get("moonsource_jdread")
return { return {
id = "ext.jdread", id = "jdread",
name = _("京东读书"), name = _("京东读书"),
type = "chapter", type = "chapter",
description = _("京东读书书架与在线阅读"), description = _("京东读书书架与在线阅读"),
@@ -34,15 +34,15 @@ local TICKET_ERRORS = {
---@return table ---@return table
local function cfg() local function cfg()
return require("utils.settings").getSource("ext.jdread") return require("utils.settings").getSource("jdread")
end end
---@param patch table ---@param patch table
local function saveCfg(patch) local function saveCfg(patch)
local Settings = require("utils.settings") local Settings = require("utils.settings")
local current = Settings.getSource("ext.jdread") local current = Settings.getSource("jdread")
for key, value in pairs(patch) do current[key] = value end for key, value in pairs(patch) do current[key] = value end
Settings.saveSource("ext.jdread", current) Settings.saveSource("jdread", current)
end end
--- 全部 Set-Cookie 行:优先 Request.headerAll(Turbo 多值 / 合并行都拆好),否则退回单值读取。 --- 全部 Set-Cookie 行:优先 Request.headerAll(Turbo 多值 / 合并行都拆好),否则退回单值读取。
@@ -118,9 +118,9 @@ end
local function nextQrFile() local function nextQrFile()
clearQrFile() clearQrFile()
local Paths = require("utils.paths") local Paths = require("utils.paths")
Paths.ensureLayout("ext.jdread") Paths.ensureLayout("jdread")
qr_seq = qr_seq + 1 qr_seq = qr_seq + 1
qr_file = Paths.imageDir("ext.jdread") .. "/login-qr-" .. qr_seq .. ".png" qr_file = Paths.imageDir("jdread") .. "/login-qr-" .. qr_seq .. ".png"
return qr_file return qr_file
end end
@@ -334,21 +334,21 @@ local function saveSessionAsync(jar, cb)
cb(false, err or _("京东登录校验失败")) cb(false, err or _("京东登录校验失败"))
return return
end end
current = require("utils.settings").getSource("ext.jdread") current = require("utils.settings").getSource("jdread")
local function commit() local function commit()
current.cookie, current.uuid, current.account_id = cookie, uuid, account_id current.cookie, current.uuid, current.account_id = cookie, uuid, account_id
current.user_name = Text.urlDecode(jar.unick or jar.pin or jar.pt_pin or "") or "" current.user_name = Text.urlDecode(jar.unick or jar.pin or jar.pt_pin or "") or ""
require("utils.settings").saveSource("ext.jdread", current) require("utils.settings").saveSource("jdread", current)
end end
if previous_id ~= account_id or not previous_id and previous_cookie ~= cookie then if previous_id ~= account_id or not previous_id and previous_cookie ~= cookie then
if not require("source.logout").replaceLibrary("ext.jdread", commit) then if not require("source.logout").replaceLibrary("jdread", commit) then
cb(false, _("准备本地同步失败")) cb(false, _("准备本地同步失败"))
return return
end end
else else
commit() commit()
end end
require("source.auth").ok("ext.jdread") require("source.auth").ok("jdread")
cb(true) cb(true)
end) end)
return { cancel = function() return { cancel = function()
@@ -26,7 +26,7 @@ local DOWNLOAD_DENIED = 101
--- 京东会话失效文案:网页 Cookie 无续期,只能引导重新扫码。 --- 京东会话失效文案:网页 Cookie 无续期,只能引导重新扫码。
local function authExpired() local function authExpired()
return require("source.auth").expire("ext.jdread", _("点这个提示上的「重新登录」。二维码出来以后,打开手机京东 App,找到「扫一扫」,对准屏幕上的二维码,在手机上点确认。")) return require("source.auth").expire("jdread", _("点这个提示上的「重新登录」。二维码出来以后,打开手机京东 App,找到「扫一扫」,对准屏幕上的二维码,在手机上点确认。"))
end end
--- 响应 message 是否表示未登录 / 会话失效。 --- 响应 message 是否表示未登录 / 会话失效。
@@ -58,7 +58,7 @@ local function decodeApi(raw, err, authed)
end end
return nil, wire.message or (_("京东读书错误 ") .. tostring(wire.result_code)) return nil, wire.message or (_("京东读书错误 ") .. tostring(wire.result_code))
end end
if authed then require("source.auth").ok("ext.jdread") end if authed then require("source.auth").ok("jdread") end
return wire return wire
end end
@@ -84,7 +84,7 @@ end
--- 会话罐:保存的 Cookie 打底,服务端轮换的会话 Cookie 留在罐里。 --- 会话罐:保存的 Cookie 打底,服务端轮换的会话 Cookie 留在罐里。
---@return CookieJar|nil ---@return CookieJar|nil
function Client:jar() function Client:jar()
return require("http.cookie_jar").session("ext.jdread", self.cookie) return require("http.cookie_jar").session("jdread", self.cookie)
end end
---@param referer string ---@param referer string
@@ -9,7 +9,7 @@ local Text = require("utils.text")
local _ = require("l10n").get("moonsource_jdread") local _ = require("l10n").get("moonsource_jdread")
local Mapper = {} local Mapper = {}
local SOURCE_ID = "ext.jdread" local SOURCE_ID = "jdread"
--- 京东图片地址带 .dpg 后缀(图床转 webp),去掉取原图。 --- 京东图片地址带 .dpg 后缀(图床转 webp),去掉取原图。
---@param value any ---@param value any
@@ -154,7 +154,7 @@ Setting.browser = {
icon = "https://e.m.jd.com/toc-web/ico.png", icon = "https://e.m.jd.com/toc-web/ico.png",
isAuthorized = function() isAuthorized = function()
return require("moonsource_jdread.auth").hasSession() return require("moonsource_jdread.auth").hasSession()
and not require("source.auth").expired("ext.jdread") and not require("source.auth").expired("jdread")
end, end,
apply = function(payload, cb) apply = function(payload, cb)
return require("moonsource_jdread.auth").importBrowserAsync(payload, function(ok, err) return require("moonsource_jdread.auth").importBrowserAsync(payload, function(ok, err)
@@ -180,7 +180,7 @@ function Setting.rows()
CookieLogin.browserRow(), CookieLogin.browserRow(),
} }
if not Auth.hasSession() then return rows end if not Auth.hasSession() then return rows end
rows[#rows + 1] = require("source.logout").row("ext.jdread", _("确定退出京东读书账号?"), Auth.clearSession) rows[#rows + 1] = require("source.logout").row("jdread", _("确定退出京东读书账号?"), Auth.clearSession)
return rows return rows
end end
@@ -35,7 +35,7 @@ Source.__index = Source
---@return JdreadSource ---@return JdreadSource
function Jdread.new() function Jdread.new()
local cfg = require("utils.settings").getSource("ext.jdread") local cfg = require("utils.settings").getSource("jdread")
local meta = Jdread.meta() local meta = Jdread.meta()
return setmetatable({ return setmetatable({
id = meta.id, id = meta.id,
@@ -279,7 +279,7 @@ local function fetchContent(self, identity, chapter, cb)
end end
asset_job = Assets.localizeAsync( asset_job = Assets.localizeAsync(
payload.html, payload.html,
Paths.bookWorkDir(identity.stable_id, "ext.jdread") .. "/images", Paths.bookWorkDir(identity.stable_id, "jdread") .. "/images",
downloadImage, downloadImage,
function(html) function(html)
if cancelled then return end if cancelled then return end
+1 -1
View File
@@ -10,7 +10,7 @@ local Config = require("support.config")
local Stubs = require("support.stubs") local Stubs = require("support.stubs")
local JSONStub = require("support.json_stub") local JSONStub = require("support.json_stub")
require("source.logout").replaceLibrary = function(id, commit) require("source.logout").replaceLibrary = function(id, commit)
Assert.eq(id, "ext.jdread") Assert.eq(id, "jdread")
commit() commit()
return true return true
end end
+1 -1
View File
@@ -298,7 +298,7 @@ do
local c = AuthClient:new{ cookie = "thor=stale", uuid = "h5-test" } local c = AuthClient:new{ cookie = "thor=stale", uuid = "h5-test" }
local got_err local got_err
c:apiGetAsync("/jdread/api/bookshelf/sort", nil, function(_wire, err) got_err = err end) c:apiGetAsync("/jdread/api/bookshelf/sort", nil, function(_wire, err) got_err = err end)
Assert.eq(expired[1].id, "ext.jdread") Assert.eq(expired[1].id, "jdread")
Assert.matches(got_err, "京东 App") Assert.matches(got_err, "京东 App")
Assert.eq(got_err, expired[1].msg) Assert.eq(got_err, expired[1].msg)
-- 中文「登录」同样走失效路径,文案仍用统一中文,不附原文 -- 中文「登录」同样走失效路径,文案仍用统一中文,不附原文
+13 -13
View File
@@ -86,7 +86,7 @@ do
} }
local BookDB = require("book.books_db") local BookDB = require("book.books_db")
BookDB.get = function(source_id, stable_id) BookDB.get = function(source_id, stable_id)
Assert.eq(source_id, "ext.jdread") Assert.eq(source_id, "jdread")
return stored[stable_id] return stored[stable_id]
end end
Assert.eq(source:coverRequest({ stable_id = "42" }).url, "https://img.jd.com/42.jpg") Assert.eq(source:coverRequest({ stable_id = "42" }).url, "https://img.jd.com/42.jpg")
@@ -176,7 +176,7 @@ do
Assert.is_nil(err) Assert.is_nil(err)
Assert.eq(result.pushed, 0) Assert.eq(result.pushed, 0)
Assert.eq(#finalized, 0) Assert.eq(#finalized, 0)
Assert.eq(warnings[1][1], "ext.jdread shelf delete push failed") Assert.eq(warnings[1][1], "jdread shelf delete push failed")
Assert.eq(warnings[1][2], "gone") Assert.eq(warnings[1][2], "gone")
pending_deletes = {} pending_deletes = {}
end end
@@ -228,7 +228,7 @@ do
require("support.stubs").flush() require("support.stubs").flush()
Assert.eq(result.pushed, 0) Assert.eq(result.pushed, 0)
Assert.eq(#synced, 0) Assert.eq(#synced, 0)
Assert.eq(warnings[1][1], "ext.jdread shelf push failed") Assert.eq(warnings[1][1], "jdread shelf push failed")
Assert.eq(warnings[1][2], "99") Assert.eq(warnings[1][2], "99")
pending_adds = {} pending_adds = {}
end end
@@ -248,7 +248,7 @@ do
src:syncBooksAsync({ dirty_only = true }, function(r) result = r end) src:syncBooksAsync({ dirty_only = true }, function(r) result = r end)
require("support.stubs").flush() require("support.stubs").flush()
Assert.eq(result.pushed, 0) Assert.eq(result.pushed, 0)
Assert.eq(warnings[1][1], "ext.jdread shelf mark synced failed") Assert.eq(warnings[1][1], "jdread shelf mark synced failed")
package.loaded["book.books_db"].markSynced = function() return true end package.loaded["book.books_db"].markSynced = function() return true end
pending_adds = {} pending_adds = {}
end end
@@ -285,7 +285,7 @@ do
end end
local progressed, ok, cached, total, failed local progressed, ok, cached, total, failed
source:cacheAllChaptersAsync( source:cacheAllChaptersAsync(
{ source_id = "ext.jdread", stable_id = "10", book = { stable_id = "10" } }, { source_id = "jdread", stable_id = "10", book = { stable_id = "10" } },
function(done, count) progressed = { done, count } end, function(done, count) progressed = { done, count } end,
function(success, count, _, all, failures) function(success, count, _, all, failures)
ok, cached, total, failed = success, count, all, failures ok, cached, total, failed = success, count, all, failures
@@ -321,7 +321,7 @@ do
end end
local src = Jdread.new() local src = Jdread.new()
src:prefetchChaptersAsync( src:prefetchChaptersAsync(
{ source_id = "ext.jdread", stable_id = "34028897", book = { stable_id = "34028897" } }, { source_id = "jdread", stable_id = "34028897", book = { stable_id = "34028897" } },
{ { idx = 1, uid = "15001647875062768", title = "第一章" } }, { { idx = 1, uid = "15001647875062768", title = "第一章" } },
1, 1, function() end 1, 1, function() end
) )
@@ -369,7 +369,7 @@ do
Assert.is_false(src:isTocCurrent({ { idx = 1, uid = "0", title = "无版本" } })) Assert.is_false(src:isTocCurrent({ { idx = 1, uid = "0", title = "无版本" } }))
Assert.is_false(src:isTocCurrent({})) Assert.is_false(src:isTocCurrent({}))
src:prefetchChaptersAsync( src:prefetchChaptersAsync(
{ source_id = "ext.jdread", stable_id = "30451107", book = { stable_id = "30451107" } }, { source_id = "jdread", stable_id = "30451107", book = { stable_id = "30451107" } },
old, 1, 1, function() end old, 1, 1, function() end
) )
Assert.eq(cleared[1], "30451107") Assert.eq(cleared[1], "30451107")
@@ -392,7 +392,7 @@ do
return { cancel = function() end } return { cancel = function() end }
end end
src:prefetchChaptersAsync( src:prefetchChaptersAsync(
{ source_id = "ext.jdread", stable_id = "30451107", book = { stable_id = "30451107" } }, { source_id = "jdread", stable_id = "30451107", book = { stable_id = "30451107" } },
stored, 1, 1, function() end stored, 1, 1, function() end
) )
Assert.eq(denied, "京东读书网页协议读不到本章,请在京东读书 App 内阅读") Assert.eq(denied, "京东读书网页协议读不到本章,请在京东读书 App 内阅读")
@@ -422,7 +422,7 @@ do
return { cancel = function() end } return { cancel = function() end }
end end
local pos local pos
Jdread.new():getProgressAsync({ source_id = "ext.jdread", stable_id = "30451107" }, function(v) pos = v end) Jdread.new():getProgressAsync({ source_id = "jdread", stable_id = "30451107" }, function(v) pos = v end)
require("support.stubs").flush() require("support.stubs").flush()
Assert.eq(pos.chapter_idx, 2) Assert.eq(pos.chapter_idx, 2)
Assert.eq(pos.extra.chapter_idx, 2) Assert.eq(pos.extra.chapter_idx, 2)
@@ -436,7 +436,7 @@ do
return { cancel = function() end } return { cancel = function() end }
end end
pos = nil pos = nil
Jdread.new():getProgressAsync({ source_id = "ext.jdread", stable_id = "30451107" }, function(v) pos = v end) Jdread.new():getProgressAsync({ source_id = "jdread", stable_id = "30451107" }, function(v) pos = v end)
require("support.stubs").flush() require("support.stubs").flush()
Assert.eq(catalog_calls, 0) Assert.eq(catalog_calls, 0)
Assert.eq(pos.fraction, 0.4) Assert.eq(pos.fraction, 0.4)
@@ -461,7 +461,7 @@ do
return { cancel = function() end } return { cancel = function() end }
end end
local src = Jdread.new() local src = Jdread.new()
local identity = { source_id = "ext.jdread", stable_id = "30451107" } local identity = { source_id = "jdread", stable_id = "30451107" }
local ok, err local ok, err
src:putProgressAsync(identity, { fraction = 0.5, chapter_idx = 2 }, function(v, e) ok, err = v, e end) src:putProgressAsync(identity, { fraction = 0.5, chapter_idx = 2 }, function(v, e) ok, err = v, e end)
Assert.is_true(ok) Assert.is_true(ok)
@@ -502,7 +502,7 @@ do
end end
require("source.assets").localizeAsync = function(raw, _, _, done) done(raw) end require("source.assets").localizeAsync = function(raw, _, _, done) done(raw) end
Jdread.new():prefetchChaptersAsync( Jdread.new():prefetchChaptersAsync(
{ source_id = "ext.jdread", stable_id = "30982479", book = { stable_id = "30982479" } }, { source_id = "jdread", stable_id = "30982479", book = { stable_id = "30982479" } },
{ { idx = 1, uid = "0", title = "封面" } }, 1, 1, function() end { { idx = 1, uid = "0", title = "封面" } }, 1, 1, function() end
) )
Assert.eq(html, '<p><img src="https://img.test/c.jpg"/></p>') Assert.eq(html, '<p><img src="https://img.test/c.jpg"/></p>')
@@ -538,7 +538,7 @@ do
opened = opened + 1 opened = opened + 1
return { cancel = function() end } return { cancel = function() end }
end end
local identity = { source_id = "ext.jdread", stable_id = "30982479" } local identity = { source_id = "jdread", stable_id = "30982479" }
local src = Jdread.new() local src = Jdread.new()
old = { old = {
+1 -1
View File
@@ -23,7 +23,7 @@ do
{ ebook_id = 30394360, name = "无封面无分类" }, { ebook_id = 30394360, name = "无封面无分类" },
}) })
Assert.len(books, 2) Assert.len(books, 2)
Assert.eq(books[1].source_id, "ext.jdread") Assert.eq(books[1].source_id, "jdread")
Assert.eq(books[1].stable_id, "30451107") Assert.eq(books[1].stable_id, "30451107")
Assert.eq(books[1].title, "H5匠人手册:霸屏H5实战解密") Assert.eq(books[1].title, "H5匠人手册:霸屏H5实战解密")
Assert.eq(books[1].authors, "网易传媒设计中心") Assert.eq(books[1].authors, "网易传媒设计中心")
+1 -1
View File
@@ -19,7 +19,7 @@ package.loaded["http.request"] = {
local Source = require("moonsource_jdread.source").new() local Source = require("moonsource_jdread.source").new()
Source._client.cookie, Source._client.uuid = "test-cookie", "test-uuid" Source._client.cookie, Source._client.uuid = "test-cookie", "test-uuid"
local Mapper = require("moonsource_jdread.mapper") local Mapper = require("moonsource_jdread.mapper")
local identity = { source_id = "ext.jdread", stable_id = "review-test", chapter_idx = 1 } local identity = { source_id = "jdread", stable_id = "review-test", chapter_idx = 1 }
---@type table|nil ---@type table|nil
local page local page
local err local err
+2 -2
View File
@@ -167,7 +167,7 @@ rows[3](300).callback()
Assert.is_false(cleared) Assert.is_false(cleared)
Themed.last("confirm").ok_callback() Themed.last("confirm").ok_callback()
Assert.is_true(cleared) Assert.is_true(cleared)
Assert.eq(forgotten, "ext.jdread") Assert.eq(forgotten, "jdread")
Assert.eq(cancelled[1], "dirty\0ext.jdread") Assert.eq(cancelled[1], "dirty\0jdread")
Assert.eq(reloads, 2) Assert.eq(reloads, 2)
Assert.len(Setting.rows(), 2) Assert.len(Setting.rows(), 2)
+5 -5
View File
@@ -17,7 +17,7 @@ local DB = require("utils.db")
local BookDB = require("book.books_db") local BookDB = require("book.books_db")
for idx = 1, 3 do for idx = 1, 3 do
Assert.is_true(BookDB.upsertRemote({ Assert.is_true(BookDB.upsertRemote({
source_id = "ext.jdread", stable_id = tostring(idx), title = "书" .. idx, deleted = 0, source_id = "jdread", stable_id = tostring(idx), title = "书" .. idx, deleted = 0,
})) }))
end end
local client = require("moonsource_jdread.client"):new{ cookie = "test", uuid = "test" } local client = require("moonsource_jdread.client"):new{ cookie = "test", uuid = "test" }
@@ -34,7 +34,7 @@ function client:apiGetAsync(request_path, _query, cb)
end end
local function sync() local function sync()
local result, reason local result, reason
require("source.shelf").syncAsync("ext.jdread", client, require("moonsource_jdread.mapper").shelfList, require("source.shelf").syncAsync("jdread", client, require("moonsource_jdread.mapper").shelfList,
{ force = true }, function(value, err) result, reason = value, err end) { force = true }, function(value, err) result, reason = value, err end)
Stubs.flush() Stubs.flush()
Assert.is_nil(reason) Assert.is_nil(reason)
@@ -42,12 +42,12 @@ local function sync()
return result return result
end end
local result = sync() local result = sync()
Assert.eq(BookDB.get("ext.jdread", "1").title, "一", "合法成员照常更新") Assert.eq(BookDB.get("jdread", "1").title, "一", "合法成员照常更新")
Assert.eq(BookDB.get("ext.jdread", "2").deleted, 0, "坏行不是远端明确移除") Assert.eq(BookDB.get("jdread", "2").deleted, 0, "坏行不是远端明确移除")
Assert.eq(result.hidden, 0) Assert.eq(result.hidden, 0)
partial = false partial = false
result = sync() result = sync()
Assert.eq(BookDB.get("ext.jdread", "2").deleted, 1, "完整快照仍按缺席下架") Assert.eq(BookDB.get("jdread", "2").deleted, 1, "完整快照仍按缺席下架")
Assert.eq(result.hidden, 1) Assert.eq(result.hidden, 1)
DB.close() DB.close()
for _idx, suffix in ipairs({ "", "-wal", "-shm" }) do os.remove(path .. suffix) end for _idx, suffix in ipairs({ "", "-wal", "-shm" }) do os.remove(path .. suffix) end