♻️ 书源 id 去掉 ext. 前缀,沿用旧内置源数据
Co-authored-by: Copilot <[email protected]>
This commit is contained in:
1 parent
1698ed8412
commit
c029847ffd
10 files changed
+23
-23
No files matched your search
@@ -3,7 +3,7 @@
|
|||||||
--]]
|
--]]
|
||||||
|
|
||||||
-- 本源的段评可借给本地书(reader.paragraph_lender)
|
-- 本源的段评可借给本地书(reader.paragraph_lender)
|
||||||
require("utils.extension").add("reader.paragraph_lender", { id = "ext.douban", label = require("moonsource_douban._meta").name })
|
require("utils.extension").add("reader.paragraph_lender", { id = "douban", label = require("moonsource_douban._meta").name })
|
||||||
|
|
||||||
local function lazy(module)
|
local function lazy(module)
|
||||||
return setmetatable({}, { __index = function(_, key) return require(module)[key] end })
|
return setmetatable({}, { __index = function(_, key) return require(module)[key] end })
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
local _ = require("l10n").get("moonsource_douban")
|
local _ = require("l10n").get("moonsource_douban")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id = "ext.douban",
|
id = "douban",
|
||||||
name = _("豆瓣阅读"),
|
name = _("豆瓣阅读"),
|
||||||
type = "chapter",
|
type = "chapter",
|
||||||
description = _("豆瓣阅读书架与在线阅读"),
|
description = _("豆瓣阅读书架与在线阅读"),
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ local _ = require("l10n").get("moonsource_douban")
|
|||||||
|
|
||||||
local Client = {}
|
local Client = {}
|
||||||
|
|
||||||
local SOURCE_ID = "ext.douban"
|
local SOURCE_ID = "douban"
|
||||||
local READ_HOST = "read.douban.com"
|
local READ_HOST = "read.douban.com"
|
||||||
local ACCOUNT_HOST = "accounts.arkread.com"
|
local ACCOUNT_HOST = "accounts.arkread.com"
|
||||||
local READ = "https://" .. READ_HOST
|
local READ = "https://" .. READ_HOST
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ local _ = require("l10n").get("moonsource_douban")
|
|||||||
|
|
||||||
local Mapper = {}
|
local Mapper = {}
|
||||||
|
|
||||||
local SOURCE_ID = "ext.douban"
|
local SOURCE_ID = "douban"
|
||||||
|
|
||||||
Mapper.TOC_VERSION = 2
|
Mapper.TOC_VERSION = 2
|
||||||
Mapper.SEARCH_HASH = "sha256:92911ffc68782f44a56764094edc0068f283c29fb447277f8ed2911af6bbd0a0"
|
Mapper.SEARCH_HASH = "sha256:92911ffc68782f44a56764094edc0068f283c29fb447277f8ed2911af6bbd0a0"
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
local _ = require("l10n").get("moonsource_douban")
|
local _ = require("l10n").get("moonsource_douban")
|
||||||
local CookieLogin = require("source.cookie_login")
|
local CookieLogin = require("source.cookie_login")
|
||||||
|
|
||||||
local SOURCE_ID = "ext.douban"
|
local SOURCE_ID = "douban"
|
||||||
local Setting = {}
|
local Setting = {}
|
||||||
local LOGIN_URL = "https://read.douban.com/oidc/login"
|
local LOGIN_URL = "https://read.douban.com/oidc/login"
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ function source:loadTocAsync(_identity, cb)
|
|||||||
return { cancel = function() end }
|
return { cancel = function() end }
|
||||||
end
|
end
|
||||||
local page, err
|
local page, err
|
||||||
source:bookReviewsAsync({ source_id = "ext.douban", stable_id = "101" }, function(value, reason)
|
source:bookReviewsAsync({ source_id = "douban", stable_id = "101" }, function(value, reason)
|
||||||
page, err = value, reason
|
page, err = value, reason
|
||||||
end)
|
end)
|
||||||
Assert.is_nil(err)
|
Assert.is_nil(err)
|
||||||
@@ -65,7 +65,7 @@ Assert.matches(page.items[1].text, "Review")
|
|||||||
Assert.is_false(page.items[1].text:find("<p>", 1, true) ~= nil)
|
Assert.is_false(page.items[1].text:find("<p>", 1, true) ~= nil)
|
||||||
Assert.is_nil(requests[1].opts.headers.Cookie)
|
Assert.is_nil(requests[1].opts.headers.Cookie)
|
||||||
Assert.eq(JSON.decode(requests[1].opts.body).variables.worksId, "101")
|
Assert.eq(JSON.decode(requests[1].opts.body).variables.worksId, "101")
|
||||||
local identity = { source_id = "ext.douban", stable_id = "101", chapter_idx = 1 }
|
local identity = { source_id = "douban", stable_id = "101", chapter_idx = 1 }
|
||||||
source:paragraphReviewPageAsync(identity, "chapter", 0, function(value, reason) page, err = value, reason end)
|
source:paragraphReviewPageAsync(identity, "chapter", 0, function(value, reason) page, err = value, reason end)
|
||||||
Assert.is_nil(err)
|
Assert.is_nil(err)
|
||||||
Assert.len(page.items, 20)
|
Assert.len(page.items, 20)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ function source:loadTocAsync(_identity, cb)
|
|||||||
return { cancel = function() end }
|
return { cancel = function() end }
|
||||||
end
|
end
|
||||||
for _idx, method in ipairs({ "paragraphHotspotsAsync", "paragraphReviewPageAsync" }) do
|
for _idx, method in ipairs({ "paragraphHotspotsAsync", "paragraphReviewPageAsync" }) do
|
||||||
local identity = { source_id = "ext.douban", stable_id = "test", chapter_idx = 1 }
|
local identity = { source_id = "douban", stable_id = "test", chapter_idx = 1 }
|
||||||
local handle
|
local handle
|
||||||
if method == "paragraphHotspotsAsync" then
|
if method == "paragraphHotspotsAsync" then
|
||||||
handle = source:paragraphHotspotsAsync(identity, function() calls = calls + 1 end)
|
handle = source:paragraphHotspotsAsync(identity, function() calls = calls + 1 end)
|
||||||
|
|||||||
@@ -51,9 +51,9 @@ Assert.is_nil(Mapper.shelfWorks(works, groups, { "1", "missing" }))
|
|||||||
Assert.is_nil(Mapper.shelfIds({ worksIds = { "1", false } }))
|
Assert.is_nil(Mapper.shelfIds({ worksIds = { "1", false } }))
|
||||||
|
|
||||||
local BookDB = require("book.books_db")
|
local BookDB = require("book.books_db")
|
||||||
Assert.is_true(BookDB.upsertRemote({ source_id = "ext.douban", stable_id = "2", title = "乙", category = "旧题材" }))
|
Assert.is_true(BookDB.upsertRemote({ source_id = "douban", stable_id = "2", title = "乙", category = "旧题材" }))
|
||||||
Assert.is_true(BookDB.upsertRemote(Mapper.shelfWorks(works, groups)[2]))
|
Assert.is_true(BookDB.upsertRemote(Mapper.shelfWorks(works, groups)[2]))
|
||||||
Assert.is_nil(BookDB.get("ext.douban", "2").category)
|
Assert.is_nil(BookDB.get("douban", "2").category)
|
||||||
|
|
||||||
local requests, deferred, defer_works = {}, false, false
|
local requests, deferred, defer_works = {}, false, false
|
||||||
local folder_wire, folder_error = { folderIds = { 10, 20 } }, nil
|
local folder_wire, folder_error = { folderIds = { 10, 20 } }, nil
|
||||||
|
|||||||
+12
-12
@@ -36,22 +36,22 @@ wire.data.user.readingTimeHistory[2].readingTime.duration = -1
|
|||||||
Assert.is_nil(Mapper.readingStats(wire, "2026-10-09", now))
|
Assert.is_nil(Mapper.readingStats(wire, "2026-10-09", now))
|
||||||
wire.data.user.readingTimeHistory[2].readingTime.duration = 1200
|
wire.data.user.readingTimeHistory[2].readingTime.duration = 1200
|
||||||
|
|
||||||
Assert.is_true(StatsDB.removeSource("ext.douban"))
|
Assert.is_true(StatsDB.removeSource("douban"))
|
||||||
Assert.is_true(StatsDB.add({
|
Assert.is_true(StatsDB.add({
|
||||||
source_id = "ext.douban", stable_id = "test-book", record_type = "page",
|
source_id = "douban", stable_id = "test-book", record_type = "page",
|
||||||
start_time = now - 600, duration = 60, page = 1, total_pages = 10,
|
start_time = now - 600, duration = 60, page = 1, total_pages = 10,
|
||||||
}, StatsDB.PENDING))
|
}, StatsDB.PENDING))
|
||||||
Assert.is_true(StatsDB.replaceSynced("ext.douban", snapshot.replace, snapshot.rows) ~= nil)
|
Assert.is_true(StatsDB.replaceSynced("douban", snapshot.replace, snapshot.rows) ~= nil)
|
||||||
Assert.eq(StatsDB.summaryBySource("ext.douban").total_seconds, 7260)
|
Assert.eq(StatsDB.summaryBySource("douban").total_seconds, 7260)
|
||||||
Assert.eq(StatsDB.dailyBySource("ext.douban")[2].seconds, 1260)
|
Assert.eq(StatsDB.dailyBySource("douban")[2].seconds, 1260)
|
||||||
Assert.eq(#StatsDB.unsyncedBySource("ext.douban", 200), 1)
|
Assert.eq(#StatsDB.unsyncedBySource("douban", 200), 1)
|
||||||
Assert.is_true(StatsDB.replaceSynced("ext.douban", snapshot.replace, snapshot.rows) ~= nil)
|
Assert.is_true(StatsDB.replaceSynced("douban", snapshot.replace, snapshot.rows) ~= nil)
|
||||||
Assert.eq(StatsDB.summaryBySource("ext.douban").total_seconds, 7260)
|
Assert.eq(StatsDB.summaryBySource("douban").total_seconds, 7260)
|
||||||
wire.data.user.readingTimeHistory[1].readingTime.duration = 0
|
wire.data.user.readingTimeHistory[1].readingTime.duration = 0
|
||||||
snapshot = Mapper.readingStats(wire, "2026-10-09", now)
|
snapshot = Mapper.readingStats(wire, "2026-10-09", now)
|
||||||
Assert.is_true(StatsDB.replaceSynced("ext.douban", snapshot.replace, snapshot.rows) ~= nil)
|
Assert.is_true(StatsDB.replaceSynced("douban", snapshot.replace, snapshot.rows) ~= nil)
|
||||||
Assert.eq(#StatsDB.dailyBySource("ext.douban"), 1)
|
Assert.eq(#StatsDB.dailyBySource("douban"), 1)
|
||||||
Assert.eq(StatsDB.summaryBySource("ext.douban").total_pages, 1)
|
Assert.eq(StatsDB.summaryBySource("douban").total_pages, 1)
|
||||||
|
|
||||||
local request
|
local request
|
||||||
package.preload["utils.settings"] = function()
|
package.preload["utils.settings"] = function()
|
||||||
@@ -79,4 +79,4 @@ Assert.eq(payload.variables.userId, "42")
|
|||||||
Assert.is_true(payload.variables.beginDate:match("^%d%d%d%d%-%d%d%-%d%d$") ~= nil)
|
Assert.is_true(payload.variables.beginDate:match("^%d%d%d%d%-%d%d%-%d%d$") ~= nil)
|
||||||
Assert.eq(request.headers["X-CSRF-Token"], "test")
|
Assert.eq(request.headers["X-CSRF-Token"], "test")
|
||||||
Assert.eq(payload.extensions.persistedQuery.sha256Hash, Mapper.READING_TIME_HASH)
|
Assert.eq(payload.extensions.persistedQuery.sha256Hash, Mapper.READING_TIME_HASH)
|
||||||
StatsDB.removeSource("ext.douban")
|
StatsDB.removeSource("douban")
|
||||||
@@ -37,7 +37,7 @@ package.preload["source.toc"] = function()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
local source = require("moonsource_douban.source").new()
|
local source = require("moonsource_douban.source").new()
|
||||||
local identity = { source_id = "ext.douban", stable_id = "test" }
|
local identity = { source_id = "douban", stable_id = "test" }
|
||||||
local result
|
local result
|
||||||
source:loadTocAsync(identity, function(toc) result = toc end)
|
source:loadTocAsync(identity, function(toc) result = toc end)
|
||||||
Stubs.flush()
|
Stubs.flush()
|
||||||
|
|||||||
Reference in new issue
Block a user