♻️ 书源 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 6379a117c2
commit 0174664163
15 files changed
+47 -47

No files matched your search

@@ -9,7 +9,7 @@
local _ = require("l10n").get("moonsource_zhihu") local _ = require("l10n").get("moonsource_zhihu")
return { return {
id = "ext.zhihu", id = "zhihu",
name = _("知乎盐选"), name = _("知乎盐选"),
type = "chapter", type = "chapter",
description = _("知乎盐选在线阅读"), description = _("知乎盐选在线阅读"),
@@ -21,7 +21,7 @@ local Client = {}
local API = "https://api.zhihu.com" local API = "https://api.zhihu.com"
local WEB = "https://www.zhihu.com" local WEB = "https://www.zhihu.com"
local UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" local UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
local SOURCE_ID = "ext.zhihu" local SOURCE_ID = "zhihu"
local CAPTCHA = "https://captcha.zhihu.com/api/v1/captcha" local CAPTCHA = "https://captcha.zhihu.com/api/v1/captcha"
local CAPTCHA_APP = "lsxNQs26Wva2" local CAPTCHA_APP = "lsxNQs26Wva2"
@@ -34,7 +34,7 @@ local CAPTCHA_APP = "lsxNQs26Wva2"
---@return string|nil ---@return string|nil
function Client.cookie() function Client.cookie()
local cookie = require("utils.settings").getSource("ext.zhihu").cookie local cookie = require("utils.settings").getSource("zhihu").cookie
return type(cookie) == "string" and cookie ~= "" and cookie or nil return type(cookie) == "string" and cookie ~= "" and cookie or nil
end end
@@ -66,7 +66,7 @@ local function get(url, headers, cb)
local cookie = Client.cookie() local cookie = Client.cookie()
return Request.get(url, opts(withCookie(headers)), function(body, err, res) return Request.get(url, opts(withCookie(headers)), function(body, err, res)
if res and tonumber(res.code) == 401 and cookie and cookie == Client.cookie() then if res and tonumber(res.code) == 401 and cookie and cookie == Client.cookie() then
cb(nil, require("source.auth").expire("ext.zhihu", _("知乎登录已失效,请重新登录"))) cb(nil, require("source.auth").expire("zhihu", _("知乎登录已失效,请重新登录")))
return return
end end
cb(body, err) cb(body, err)
@@ -377,7 +377,7 @@ function Client.putProgressAsync(section_id, fraction, cb)
["Content-Type"] = "application/json", Referer = WEB .. "/", ["Content-Type"] = "application/json", Referer = WEB .. "/",
})), function(raw, err, res) })), function(raw, err, res)
if res and tonumber(res.code) == 401 and cookie == Client.cookie() then if res and tonumber(res.code) == 401 and cookie == Client.cookie() then
cb(nil, require("source.auth").expire("ext.zhihu", _("知乎登录已失效,请重新登录"))) cb(nil, require("source.auth").expire("zhihu", _("知乎登录已失效,请重新登录")))
return return
end end
local wire = decode(raw) local wire = decode(raw)
@@ -12,7 +12,7 @@ local Text = require("utils.text")
local Mapper = {} local Mapper = {}
Mapper.TOC_VERSION = 1 Mapper.TOC_VERSION = 1
local SOURCE_ID = "ext.zhihu" local SOURCE_ID = "zhihu"
---@param value any ---@param value any
---@return string ---@return string
@@ -15,7 +15,7 @@ end
---@type CookieLoginSpec ---@type CookieLoginSpec
local SPEC = { local SPEC = {
id = "ext.zhihu", id = "zhihu",
title = _("知乎账号"), title = _("知乎账号"),
cookie_title = _("知乎登录 Cookie"), cookie_title = _("知乎登录 Cookie"),
cookie_hint = _("按键盘 F12,点「网络」,刷新网页,复制请求标头里的整段 Cookie"), cookie_hint = _("按键盘 F12,点「网络」,刷新网页,复制请求标头里的整段 Cookie"),
@@ -44,7 +44,7 @@ Setting.browser = {
local function showLogin() local function showLogin()
require("ui/network/manager"):runWhenConnected(function() require("ui/network/manager"):runWhenConnected(function()
require("moonsource_zhihu.qrlogin"):new(function() require("moonsource_zhihu.qrlogin"):new(function()
require("source.auth").ok("ext.zhihu") require("source.auth").ok("zhihu")
require("source.registry").reload() require("source.registry").reload()
require("ui.themes.widgets.toast"):new{ text = _("登录成功"), timeout = 2 }:show() require("ui.themes.widgets.toast"):new{ text = _("登录成功"), timeout = 2 }:show()
end):start() end):start()
@@ -59,7 +59,7 @@ function Setting.rows(plugin)
}), }),
CookieLogin.browserRow(), CookieLogin.browserRow(),
CookieLogin.pasteRow(SPEC), CookieLogin.pasteRow(SPEC),
require("source.review_setting").row("ext.zhihu", plugin), require("source.review_setting").row("zhihu", plugin),
} }
if loggedIn() then rows[#rows + 1] = CookieLogin.logoutRow(SPEC) end if loggedIn() then rows[#rows + 1] = CookieLogin.logoutRow(SPEC) end
return rows return rows
@@ -149,7 +149,7 @@ local function fetcher(open)
return function(identity, chapter, done) return function(identity, chapter, done)
local function finish(html, err) local function finish(html, err)
if html then if html then
if chapter.vip then Toc.markPaid("ext.zhihu", identity.stable_id, chapter.uid, true) end if chapter.vip then Toc.markPaid("zhihu", identity.stable_id, chapter.uid, true) end
done({ title = chapter.title, html = require("moonsource_zhihu.content").prepare(html) }) done({ title = chapter.title, html = require("moonsource_zhihu.content").prepare(html) })
return return
end end
+5 -5
View File
@@ -14,7 +14,7 @@ local catalog = {
package.loaded["moonsource_zhihu.client"] = { package.loaded["moonsource_zhihu.client"] = {
browseAsync = function(rank, filter, cb) browseAsync = function(rank, filter, cb)
selected = rank .. ":" .. filter selected = rank .. ":" .. filter
cb(not failure and { { source_id = "ext.zhihu", stable_id = "1/2", title = "条目" } } or nil, failure, { cb(not failure and { { source_id = "zhihu", stable_id = "1/2", title = "条目" } } or nil, failure, {
{ key = "0", name = "全部" }, { key = "12", name = " 脑洞 " }, { key = "999", name = "新分类" }, { key = "0", name = "全部" }, { key = "12", name = " 脑洞 " }, { key = "999", name = "新分类" },
}) })
return { cancel = function() cancelled = true end } return { cancel = function() cancelled = true end }
@@ -22,8 +22,8 @@ package.loaded["moonsource_zhihu.client"] = {
catalogAsync = function(id, cb) called = id; cb(catalog); return {} end, catalogAsync = function(id, cb) called = id; cb(catalog); return {} end,
detailAsync = function(id, cb) detailAsync = function(id, cb)
called = "detail:" .. id called = "detail:" .. id
cb({ source_id = "ext.zhihu", stable_id = id, title = "长篇标题", authors = "作者", cb({ source_id = "zhihu", stable_id = id, title = "长篇标题", authors = "作者",
cover = "https://img/column.jpg", intro = "完整简介", meta = { rating = { score = 8.9, by = "ext.zhihu" } } }) cover = "https://img/column.jpg", intro = "完整简介", meta = { rating = { score = 8.9, by = "zhihu" } } })
return {} return {}
end, end,
simpleAsync = function() error("长篇不能调用单节接口") end, simpleAsync = function() error("长篇不能调用单节接口") end,
@@ -60,12 +60,12 @@ Assert.is_nil(result)
Assert.eq(err, failure) Assert.eq(err, failure)
failure = nil failure = nil
local identity = { source_id = "ext.zhihu", stable_id = "11" } local identity = { source_id = "zhihu", stable_id = "11" }
source:loadTocAsync(identity, function(value) result = value end) source:loadTocAsync(identity, function(value) result = value end)
Assert.eq(called, "11") Assert.eq(called, "11")
Assert.eq(result[1].uid, "22") Assert.eq(result[1].uid, "22")
Assert.eq(saved.stable_id, "11") Assert.eq(saved.stable_id, "11")
Assert.eq(saved.source_id, "ext.zhihu") Assert.eq(saved.source_id, "zhihu")
source:getDetailAsync(identity, function(value) result = value end) source:getDetailAsync(identity, function(value) result = value end)
Assert.eq(called, "detail:11", "详情走书籍接口,不用目录的精简元数据或榜单片段") Assert.eq(called, "detail:11", "详情走书籍接口,不用目录的精简元数据或榜单片段")
Assert.eq(result.stable_id, "11") Assert.eq(result.stable_id, "11")
+4 -4
View File
@@ -83,7 +83,7 @@ local folded = Mapper.chapters({ is_fold = true, section = { title = "红包不
Assert.eq(folded[1].vip, true) Assert.eq(folded[1].vip, true)
local detail = Mapper.detail(simple, "1580618311758471168/1598363011911184384") local detail = Mapper.detail(simple, "1580618311758471168/1598363011911184384")
Assert.eq(detail.cover, "https://img/c.jpg") Assert.eq(detail.cover, "https://img/c.jpg")
Assert.eq(detail.source_id, "ext.zhihu") Assert.eq(detail.source_id, "zhihu")
local requests = {} local requests = {}
local request_options = {} local request_options = {}
@@ -143,7 +143,7 @@ Assert.eq(request_options[#request_options].headers["x-zse-93"], "101_3_3.1")
Assert.matches(request_options[#request_options].headers["x-zse-96"], "^2%.0_.+") Assert.matches(request_options[#request_options].headers["x-zse-96"], "^2%.0_.+")
local Settings = require("utils.settings") local Settings = require("utils.settings")
local cfg = Settings.getSource("ext.zhihu") local cfg = Settings.getSource("zhihu")
cfg.cookie = "z_c0=saved" cfg.cookie = "z_c0=saved"
local verified, verify_error local verified, verify_error
Client.loginCheckAsync("z_c0=candidate", function(ok, err) verified, verify_error = ok, err end) Client.loginCheckAsync("z_c0=candidate", function(ok, err) verified, verify_error = ok, err end)
@@ -174,8 +174,8 @@ local Auth = require("source.auth")
Auth.reset() Auth.reset()
response_code = 401 response_code = 401
Client.searchAsync("红包", function(_books, err) verify_error = err end) Client.searchAsync("红包", function(_books, err) verify_error = err end)
Assert.is_true(Auth.expired("ext.zhihu")) Assert.is_true(Auth.expired("zhihu"))
Assert.eq(verify_error, "知乎登录已失效,请重新登录") Assert.eq(verify_error, "知乎登录已失效,请重新登录")
cfg.cookie = nil cfg.cookie = nil
Settings.saveSource("ext.zhihu") Settings.saveSource("zhihu")
Auth.reset() Auth.reset()
+3 -3
View File
@@ -43,7 +43,7 @@ package.preload["moonsource_zhihu.font"] = function()
end end
local Settings = require("utils.settings") local Settings = require("utils.settings")
Settings.getSource("ext.zhihu").cookie = 'z_c0=saved; d_c0="fixture|1"' Settings.getSource("zhihu").cookie = 'z_c0=saved; d_c0="fixture|1"'
local Client = require("moonsource_zhihu.client") local Client = require("moonsource_zhihu.client")
local value, error_message, completed local value, error_message, completed
local function fetch() local function fetch()
@@ -57,7 +57,7 @@ response = Json.encode({ is_fold = false, authentication_result = true, manuscri
fetch() fetch()
Assert.eq(value, "<p>正文</p>") Assert.eq(value, "<p>正文</p>")
Assert.eq(requested_path, "/remix-web/paid_columns/1/sections/2/manuscript?v=1&manuscript_version=0") Assert.eq(requested_path, "/remix-web/paid_columns/1/sections/2/manuscript?v=1&manuscript_version=0")
Assert.eq(signed_cookie, Settings.getSource("ext.zhihu").cookie) Assert.eq(signed_cookie, Settings.getSource("zhihu").cookie)
Assert.eq(request_options.headers.Cookie, signed_cookie) Assert.eq(request_options.headers.Cookie, signed_cookie)
Assert.eq(request_options.headers["x-zse-96"], "fixture") Assert.eq(request_options.headers["x-zse-96"], "fixture")
Assert.eq(calls, 0, "没有乱序字体的章节不创建字体任务") Assert.eq(calls, 0, "没有乱序字体的章节不创建字体任务")
@@ -115,4 +115,4 @@ handle.cancel()
Assert.eq(http_cancelled, 1) Assert.eq(http_cancelled, 1)
http_cb(response) http_cb(response)
Assert.eq(completed, 0, "取消 HTTP 后忽略迟到响应") Assert.eq(completed, 0, "取消 HTTP 后忽略迟到响应")
Settings.getSource("ext.zhihu").cookie = nil Settings.getSource("zhihu").cookie = nil
+7 -7
View File
@@ -23,7 +23,7 @@ Assert.eq(book.authors, "作者甲、作者乙")
Assert.eq(book.intro, "宣传语 & 引言\n\n第一段。\n第二段:完整简介结尾。") Assert.eq(book.intro, "宣传语 & 引言\n\n第一段。\n第二段:完整简介结尾。")
Assert.eq(book.cover, wire.artwork) Assert.eq(book.cover, wire.artwork)
Assert.eq(book.meta.rating.score, 8.9) Assert.eq(book.meta.rating.score, 8.9)
Assert.eq(book.meta.rating.by, "ext.zhihu") Assert.eq(book.meta.rating.by, "zhihu")
Assert.is_nil(Mapper.detail({ error = { code = 1 }, title = "错误" }, "11")) Assert.is_nil(Mapper.detail({ error = { code = 1 }, title = "错误" }, "11"))
Assert.is_nil(Mapper.detail(wire, "11", { show_score = false, score = "8.9" }).meta) Assert.is_nil(Mapper.detail(wire, "11", { show_score = false, score = "8.9" }).meta)
Assert.is_nil(Mapper.detail(wire, "11", { show_score = true, score = "11" }).meta) Assert.is_nil(Mapper.detail(wire, "11", { show_score = true, score = "11" }).meta)
@@ -42,7 +42,7 @@ package.loaded["http.request"] = {
end, end,
} }
local Settings = require("utils.settings") local Settings = require("utils.settings")
Settings.getSource("ext.zhihu").cookie = "z_c0=fixture" Settings.getSource("zhihu").cookie = "z_c0=fixture"
local Client = require("moonsource_zhihu.client") local Client = require("moonsource_zhihu.client")
local result, err, calls = nil, nil, 0 local result, err, calls = nil, nil, 0
local function done(value, reason) result, err, calls = value, reason, calls + 1 end local function done(value, reason) result, err, calls = value, reason, calls + 1 end
@@ -79,20 +79,20 @@ pending[#pending].cb(JSON.encode(grading))
Assert.eq(calls, before, "取消后迟到的评分不能更新详情") Assert.eq(calls, before, "取消后迟到的评分不能更新详情")
local BookDB = require("book.books_db") local BookDB = require("book.books_db")
Assert.is_true(BookDB.upsertLocal({ source_id = "ext.zhihu", stable_id = "11", title = "本地书名", category = "本地分类" })) Assert.is_true(BookDB.upsertLocal({ source_id = "zhihu", stable_id = "11", title = "本地书名", category = "本地分类" }))
package.loaded["moonsource_zhihu.client"] = { package.loaded["moonsource_zhihu.client"] = {
detailAsync = function(id, cb) cb(Mapper.detail(wire, id, grading)); return {} end, detailAsync = function(id, cb) cb(Mapper.detail(wire, id, grading)); return {} end,
} }
local source = require("moonsource_zhihu.source").new() local source = require("moonsource_zhihu.source").new()
source:getDetailAsync({ source_id = "ext.zhihu", stable_id = "11" }, done) source:getDetailAsync({ source_id = "zhihu", stable_id = "11" }, done)
Assert.eq(result.authors, "作者甲、作者乙", "本地上架的脏行也要补缺失作者") Assert.eq(result.authors, "作者甲、作者乙", "本地上架的脏行也要补缺失作者")
Assert.eq(result.intro, book.intro, "本地上架时没有简介,详情必须补全并落盘") Assert.eq(result.intro, book.intro, "本地上架时没有简介,详情必须补全并落盘")
Assert.eq(result.title, "本地书名") Assert.eq(result.title, "本地书名")
Assert.eq(result.category, "本地分类") Assert.eq(result.category, "本地分类")
Assert.eq(result.sync_status, 0) Assert.eq(result.sync_status, 0)
Assert.is_true(BookDB.upsertLocal({ source_id = "ext.zhihu", stable_id = "11", title = "自定义书名", Assert.is_true(BookDB.upsertLocal({ source_id = "zhihu", stable_id = "11", title = "自定义书名",
authors = "自定义作者", intro = "自定义简介", category = "本地分类" })) authors = "自定义作者", intro = "自定义简介", category = "本地分类" }))
source:getDetailAsync({ source_id = "ext.zhihu", stable_id = "11" }, done) source:getDetailAsync({ source_id = "zhihu", stable_id = "11" }, done)
Assert.eq(result.authors, "自定义作者") Assert.eq(result.authors, "自定义作者")
Assert.eq(result.intro, "自定义简介", "自动补全不能覆盖已编辑的非空字段") Assert.eq(result.intro, "自定义简介", "自动补全不能覆盖已编辑的非空字段")
Settings.getSource("ext.zhihu").cookie = nil Settings.getSource("zhihu").cookie = nil
+2 -2
View File
@@ -92,7 +92,7 @@ package.loaded["http.request"] = {
} }
package.loaded["moonsource_zhihu.client"] = nil package.loaded["moonsource_zhihu.client"] = nil
local Client = require("moonsource_zhihu.client") local Client = require("moonsource_zhihu.client")
local cfg = Settings.getSource("ext.zhihu") local cfg = Settings.getSource("zhihu")
local original_cookie = cfg.cookie local original_cookie = cfg.cookie
cfg.cookie = nil cfg.cookie = nil
@@ -242,4 +242,4 @@ Assert.is_nil(warnings[#warnings]:find("private-token", 1, true))
Log.warn = original_warn Log.warn = original_warn
cfg.cookie = original_cookie cfg.cookie = original_cookie
Settings.saveSource("ext.zhihu") Settings.saveSource("zhihu")
+2 -2
View File
@@ -9,7 +9,7 @@ local Assert = require("support.assert")
local JSON = require("support.json_stub") local JSON = require("support.json_stub")
package.loaded["json"] = JSON package.loaded["json"] = JSON
local Stubs = require("support.stubs") local Stubs = require("support.stubs")
local cfg = require("utils.settings").getSource("ext.zhihu") local cfg = require("utils.settings").getSource("zhihu")
cfg.cookie = "z_c0=progress-fixture" cfg.cookie = "z_c0=progress-fixture"
local pending, sync_column = {}, false local pending, sync_column = {}, false
local function request(url, options, cb, body) local function request(url, options, cb, body)
@@ -104,7 +104,7 @@ local Auth = require("source.auth")
Auth.reset() Auth.reset()
Client.putProgressAsync("2", .4, done) Client.putProgressAsync("2", .4, done)
pending[#pending].cb(nil, "HTTP 401", { code = 401 }) pending[#pending].cb(nil, "HTTP 401", { code = 401 })
Assert.is_true(Auth.expired("ext.zhihu")) Assert.is_true(Auth.expired("zhihu"))
Auth.reset() Auth.reset()
cfg.cookie = nil cfg.cookie = nil
local count = #pending local count = #pending
+2 -2
View File
@@ -25,8 +25,8 @@ function Source:loadTocAsync(_identity, cb, force)
toc_requests[#toc_requests + 1] = item toc_requests[#toc_requests + 1] = item
return { cancel = function() item.cancelled = true end } return { cancel = function() item.cancelled = true end }
end end
local short = { source_id = "ext.zhihu", stable_id = "1/2" } local short = { source_id = "zhihu", stable_id = "1/2" }
local long = { source_id = "ext.zhihu", stable_id = "1" } local long = { source_id = "zhihu", stable_id = "1" }
local toc = { { idx = 1, uid = "2", title = "甲" }, { idx = 2, uid = "3", title = "乙" } } local toc = { { idx = 1, uid = "2", title = "甲" }, { idx = 2, uid = "3", title = "乙" } }
local result, err, calls = nil, nil, 0 local result, err, calls = nil, nil, 0
local function done(value, reason) result, err, calls = value, reason, calls + 1 end local function done(value, reason) result, err, calls = value, reason, calls + 1 end
+4 -4
View File
@@ -8,7 +8,7 @@
local Assert = require("support.assert") local Assert = require("support.assert")
local JSON = require("support.json_stub") local JSON = require("support.json_stub")
package.loaded["json"] = JSON package.loaded["json"] = JSON
local cfg = require("utils.settings").getSource("ext.zhihu") local cfg = require("utils.settings").getSource("zhihu")
cfg.cookie = "z_c0=comment-fixture" cfg.cookie = "z_c0=comment-fixture"
local pending = {} local pending = {}
package.loaded["http.request"] = { package.loaded["http.request"] = {
@@ -91,7 +91,7 @@ local Auth = require("source.auth")
Auth.reset() Auth.reset()
Client.reviewsAsync("22", 0, false, done) Client.reviewsAsync("22", 0, false, done)
pending[#pending].cb(nil, "HTTP 401", { code = 401 }) pending[#pending].cb(nil, "HTTP 401", { code = 401 })
Assert.is_true(Auth.expired("ext.zhihu")) Assert.is_true(Auth.expired("zhihu"))
Auth.reset() Auth.reset()
local cache_keys = {} local cache_keys = {}
@@ -103,7 +103,7 @@ package.loaded["book.review_cache"] = {
end, end,
} }
local source = require("moonsource_zhihu.source").new() local source = require("moonsource_zhihu.source").new()
local short = { source_id = "ext.zhihu", stable_id = "11/22", book = { title = "短篇" } } local short = { source_id = "zhihu", stable_id = "11/22", book = { title = "短篇" } }
source:chapterReviewHotspotsAsync(short, done) source:chapterReviewHotspotsAsync(short, done)
pending[#pending].cb(JSON.encode(wire())) pending[#pending].cb(JSON.encode(wire()))
Assert.len(result, 1) Assert.len(result, 1)
@@ -112,7 +112,7 @@ Assert.eq(result[1].text, "短篇")
Assert.eq(result[1].badge, "380") Assert.eq(result[1].badge, "380")
Assert.eq(result[1].heading, "章节评论") Assert.eq(result[1].heading, "章节评论")
Assert.eq(cache_keys[#cache_keys][1], short, "整篇 EPUB 不需要伪造 chapter_idx") Assert.eq(cache_keys[#cache_keys][1], short, "整篇 EPUB 不需要伪造 chapter_idx")
local long = { source_id = "ext.zhihu", stable_id = "11", chapter_idx = 2 } local long = { source_id = "zhihu", stable_id = "11", chapter_idx = 2 }
function source:loadTocAsync(_identity, cb) function source:loadTocAsync(_identity, cb)
cb({ { uid = "22", title = "第一章" }, { uid = "33", title = "第二章" } }) cb({ { uid = "22", title = "第一章" }, { uid = "33", title = "第二章" } })
return { cancel = function() error("已完成目录请求不能覆盖当前评论请求") end } return { cancel = function() error("已完成目录请求不能覆盖当前评论请求") end }
+7 -7
View File
@@ -12,7 +12,7 @@ Themed.install()
package.loaded["ui.themes.widgets.row"] = { widget = function(spec) return spec end } package.loaded["ui.themes.widgets.row"] = { widget = function(spec) return spec end }
package.loaded["ui/network/manager"] = { runWhenConnected = function(_self, fn) fn() end } package.loaded["ui/network/manager"] = { runWhenConnected = function(_self, fn) fn() end }
local cfg = Settings.getSource("ext.zhihu") local cfg = Settings.getSource("zhihu")
cfg.cookie = nil cfg.cookie = nil
cfg.show_paragraph_reviews = nil cfg.show_paragraph_reviews = nil
local checked, allow, reloads = {}, false, 0 local checked, allow, reloads = {}, false, 0
@@ -102,7 +102,7 @@ package.loaded["moonsource_zhihu.story"] = {
} }
package.loaded["source.toc"] = { package.loaded["source.toc"] = {
markPaid = function(id, stable_id, uid, value) markPaid = function(id, stable_id, uid, value)
Assert.eq(id, "ext.zhihu") Assert.eq(id, "zhihu")
Assert.eq(stable_id, "1/2") Assert.eq(stable_id, "1/2")
Assert.eq(uid, "2") Assert.eq(uid, "2")
paid = value paid = value
@@ -110,11 +110,11 @@ package.loaded["source.toc"] = {
} }
local source = require("moonsource_zhihu.source").new() local source = require("moonsource_zhihu.source").new()
Assert.is_false(source:paragraphReviewsEnabled()) Assert.is_false(source:paragraphReviewsEnabled())
require("source.review_setting").set("ext.zhihu", true) require("source.review_setting").set("zhihu", true)
Assert.is_true(source:paragraphReviewsEnabled(), "设置页和源实例读同一份开关") Assert.is_true(source:paragraphReviewsEnabled(), "设置页和源实例读同一份开关")
require("source.review_setting").set("ext.zhihu", false) require("source.review_setting").set("zhihu", false)
Assert.is_false(source:paragraphReviewsEnabled(), "开关就地生效,不必重建源实例") Assert.is_false(source:paragraphReviewsEnabled(), "开关就地生效,不必重建源实例")
local identity = { source_id = "ext.zhihu", stable_id = "1/2" } local identity = { source_id = "zhihu", stable_id = "1/2" }
local chapter = { idx = 1, uid = "2", title = "第一节", vip = true } local chapter = { idx = 1, uid = "2", title = "第一节", vip = true }
source:openBookAsync(identity, { chapter_idx = 1 }, function() end) source:openBookAsync(identity, { chapter_idx = 1 }, function() end)
local result, failure local result, failure
@@ -139,7 +139,7 @@ Assert.is_nil(result)
Assert.eq(failure, "network down") Assert.eq(failure, "network down")
html, content_error = "<p>长篇章节</p>", nil html, content_error = "<p>长篇章节</p>", nil
open_fetch({ source_id = "ext.zhihu", stable_id = "3" }, { idx = 1, uid = "4", title = "第一节" }, open_fetch({ source_id = "zhihu", stable_id = "3" }, { idx = 1, uid = "4", title = "第一节" },
function(value, err) result, failure = value, err end) function(value, err) result, failure = value, err end)
Assert.eq(content_id, "3/4", "长篇按当前章节请求正文,不把专栏 id 当作节 id") Assert.eq(content_id, "3/4", "长篇按当前章节请求正文,不把专栏 id 当作节 id")
Assert.eq(result.html, require("moonsource_zhihu.content").prepare(html)) Assert.eq(result.html, require("moonsource_zhihu.content").prepare(html))
@@ -158,4 +158,4 @@ Assert.eq(type(scanned), "function")
scanned() scanned()
Assert.eq(Themed.last("toast").text, "登录成功") Assert.eq(Themed.last("toast").text, "登录成功")
Assert.eq(reloads, 3) Assert.eq(reloads, 3)
Settings.saveSource("ext.zhihu") Settings.saveSource("zhihu")
+1 -1
View File
@@ -23,7 +23,7 @@ local BookDB = require("book.books_db")
local ProgressDB = require("book.progress_db") local ProgressDB = require("book.progress_db")
local NoteDB = require("book.note_db") local NoteDB = require("book.note_db")
local Store = require("book.store") local Store = require("book.store")
local identity = { source_id = "ext.zhihu", stable_id = "910000001/910000002" } local identity = { source_id = "zhihu", stable_id = "910000001/910000002" }
local original = Paths.chapterPath(identity.stable_id, 1, identity.source_id) local original = Paths.chapterPath(identity.stable_id, 1, identity.source_id)
local dest = Paths.bookWorkDir(identity.stable_id, identity.source_id) .. "/book.epub" local dest = Paths.bookWorkDir(identity.stable_id, identity.source_id) .. "/book.epub"
Assert.is_true(Paths.ensureDir(original:match("(.+)/[^/]+$"))) Assert.is_true(Paths.ensureDir(original:match("(.+)/[^/]+$")))