From 017466416388ff5452afee1384a497f97df7ea9f Mon Sep 17 00:00:00 2001 From: Garfield Date: Mon, 16 Nov 2026 14:07:45 +0800 Subject: [PATCH] =?UTF-8?q?:recycle:=20=E4=B9=A6=E6=BA=90=20id=20=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=20ext.=20=E5=89=8D=E7=BC=80=EF=BC=8C=E6=B2=BF?= =?UTF-8?q?=E7=94=A8=E6=97=A7=E5=86=85=E7=BD=AE=E6=BA=90=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../moonsource_zhihu/_meta.lua | 2 +- .../moonsource_zhihu/client.lua | 8 ++++---- .../moonsource_zhihu/mapper.lua | 2 +- .../moonsource_zhihu/setting.lua | 6 +++--- .../moonsource_zhihu/source.lua | 2 +- tests/zhihu/browse_spec.lua | 10 +++++----- tests/zhihu/client_spec.lua | 8 ++++---- tests/zhihu/content_spec.lua | 6 +++--- tests/zhihu/detail_spec.lua | 14 +++++++------- tests/zhihu/login_spec.lua | 4 ++-- tests/zhihu/progress_client_spec.lua | 4 ++-- tests/zhihu/progress_spec.lua | 4 ++-- tests/zhihu/reviews_spec.lua | 8 ++++---- tests/zhihu/setting_spec.lua | 14 +++++++------- tests/zhihu/story_spec.lua | 2 +- 15 files changed, 47 insertions(+), 47 deletions(-) diff --git a/moonsource-zhihu.koplugin/moonsource_zhihu/_meta.lua b/moonsource-zhihu.koplugin/moonsource_zhihu/_meta.lua index e9f7806..f47d261 100644 --- a/moonsource-zhihu.koplugin/moonsource_zhihu/_meta.lua +++ b/moonsource-zhihu.koplugin/moonsource_zhihu/_meta.lua @@ -9,7 +9,7 @@ local _ = require("l10n").get("moonsource_zhihu") return { - id = "ext.zhihu", + id = "zhihu", name = _("知乎盐选"), type = "chapter", description = _("知乎盐选在线阅读"), diff --git a/moonsource-zhihu.koplugin/moonsource_zhihu/client.lua b/moonsource-zhihu.koplugin/moonsource_zhihu/client.lua index ab7d1a5..998d48f 100644 --- a/moonsource-zhihu.koplugin/moonsource_zhihu/client.lua +++ b/moonsource-zhihu.koplugin/moonsource_zhihu/client.lua @@ -21,7 +21,7 @@ local Client = {} local API = "https://api.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 SOURCE_ID = "ext.zhihu" +local SOURCE_ID = "zhihu" local CAPTCHA = "https://captcha.zhihu.com/api/v1/captcha" local CAPTCHA_APP = "lsxNQs26Wva2" @@ -34,7 +34,7 @@ local CAPTCHA_APP = "lsxNQs26Wva2" ---@return string|nil 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 end @@ -66,7 +66,7 @@ local function get(url, headers, cb) local cookie = Client.cookie() 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 - cb(nil, require("source.auth").expire("ext.zhihu", _("知乎登录已失效,请重新登录"))) + cb(nil, require("source.auth").expire("zhihu", _("知乎登录已失效,请重新登录"))) return end cb(body, err) @@ -377,7 +377,7 @@ function Client.putProgressAsync(section_id, fraction, cb) ["Content-Type"] = "application/json", Referer = WEB .. "/", })), function(raw, err, res) 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 end local wire = decode(raw) diff --git a/moonsource-zhihu.koplugin/moonsource_zhihu/mapper.lua b/moonsource-zhihu.koplugin/moonsource_zhihu/mapper.lua index da00feb..1a2e64e 100644 --- a/moonsource-zhihu.koplugin/moonsource_zhihu/mapper.lua +++ b/moonsource-zhihu.koplugin/moonsource_zhihu/mapper.lua @@ -12,7 +12,7 @@ local Text = require("utils.text") local Mapper = {} Mapper.TOC_VERSION = 1 -local SOURCE_ID = "ext.zhihu" +local SOURCE_ID = "zhihu" ---@param value any ---@return string diff --git a/moonsource-zhihu.koplugin/moonsource_zhihu/setting.lua b/moonsource-zhihu.koplugin/moonsource_zhihu/setting.lua index 673778a..b1bbb05 100644 --- a/moonsource-zhihu.koplugin/moonsource_zhihu/setting.lua +++ b/moonsource-zhihu.koplugin/moonsource_zhihu/setting.lua @@ -15,7 +15,7 @@ end ---@type CookieLoginSpec local SPEC = { - id = "ext.zhihu", + id = "zhihu", title = _("知乎账号"), cookie_title = _("知乎登录 Cookie"), cookie_hint = _("按键盘 F12,点「网络」,刷新网页,复制请求标头里的整段 Cookie"), @@ -44,7 +44,7 @@ Setting.browser = { local function showLogin() require("ui/network/manager"):runWhenConnected(function() require("moonsource_zhihu.qrlogin"):new(function() - require("source.auth").ok("ext.zhihu") + require("source.auth").ok("zhihu") require("source.registry").reload() require("ui.themes.widgets.toast"):new{ text = _("登录成功"), timeout = 2 }:show() end):start() @@ -59,7 +59,7 @@ function Setting.rows(plugin) }), CookieLogin.browserRow(), 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 return rows diff --git a/moonsource-zhihu.koplugin/moonsource_zhihu/source.lua b/moonsource-zhihu.koplugin/moonsource_zhihu/source.lua index 0df6417..bddd6c6 100644 --- a/moonsource-zhihu.koplugin/moonsource_zhihu/source.lua +++ b/moonsource-zhihu.koplugin/moonsource_zhihu/source.lua @@ -149,7 +149,7 @@ local function fetcher(open) return function(identity, chapter, done) local function finish(html, err) 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) }) return end diff --git a/tests/zhihu/browse_spec.lua b/tests/zhihu/browse_spec.lua index 3f63a86..7c76e17 100644 --- a/tests/zhihu/browse_spec.lua +++ b/tests/zhihu/browse_spec.lua @@ -14,7 +14,7 @@ local catalog = { package.loaded["moonsource_zhihu.client"] = { browseAsync = function(rank, filter, cb) 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 = "新分类" }, }) 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, detailAsync = function(id, cb) called = "detail:" .. id - cb({ source_id = "ext.zhihu", stable_id = id, title = "长篇标题", authors = "作者", - cover = "https://img/column.jpg", intro = "完整简介", meta = { rating = { score = 8.9, by = "ext.zhihu" } } }) + cb({ source_id = "zhihu", stable_id = id, title = "长篇标题", authors = "作者", + cover = "https://img/column.jpg", intro = "完整简介", meta = { rating = { score = 8.9, by = "zhihu" } } }) return {} end, simpleAsync = function() error("长篇不能调用单节接口") end, @@ -60,12 +60,12 @@ Assert.is_nil(result) Assert.eq(err, failure) 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) Assert.eq(called, "11") Assert.eq(result[1].uid, "22") 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) Assert.eq(called, "detail:11", "详情走书籍接口,不用目录的精简元数据或榜单片段") Assert.eq(result.stable_id, "11") diff --git a/tests/zhihu/client_spec.lua b/tests/zhihu/client_spec.lua index 4bab8d2..818cf9e 100644 --- a/tests/zhihu/client_spec.lua +++ b/tests/zhihu/client_spec.lua @@ -83,7 +83,7 @@ local folded = Mapper.chapters({ is_fold = true, section = { title = "红包不 Assert.eq(folded[1].vip, true) local detail = Mapper.detail(simple, "1580618311758471168/1598363011911184384") Assert.eq(detail.cover, "https://img/c.jpg") -Assert.eq(detail.source_id, "ext.zhihu") +Assert.eq(detail.source_id, "zhihu") local requests = {} 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_.+") local Settings = require("utils.settings") -local cfg = Settings.getSource("ext.zhihu") +local cfg = Settings.getSource("zhihu") cfg.cookie = "z_c0=saved" local verified, verify_error 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() response_code = 401 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, "知乎登录已失效,请重新登录") cfg.cookie = nil -Settings.saveSource("ext.zhihu") +Settings.saveSource("zhihu") Auth.reset() diff --git a/tests/zhihu/content_spec.lua b/tests/zhihu/content_spec.lua index 6e15dea..96e07d4 100644 --- a/tests/zhihu/content_spec.lua +++ b/tests/zhihu/content_spec.lua @@ -43,7 +43,7 @@ package.preload["moonsource_zhihu.font"] = function() end 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 value, error_message, completed local function fetch() @@ -57,7 +57,7 @@ response = Json.encode({ is_fold = false, authentication_result = true, manuscri fetch() Assert.eq(value, "

正文

") 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["x-zse-96"], "fixture") Assert.eq(calls, 0, "没有乱序字体的章节不创建字体任务") @@ -115,4 +115,4 @@ handle.cancel() Assert.eq(http_cancelled, 1) http_cb(response) Assert.eq(completed, 0, "取消 HTTP 后忽略迟到响应") -Settings.getSource("ext.zhihu").cookie = nil +Settings.getSource("zhihu").cookie = nil diff --git a/tests/zhihu/detail_spec.lua b/tests/zhihu/detail_spec.lua index 4f1309b..c23da0c 100644 --- a/tests/zhihu/detail_spec.lua +++ b/tests/zhihu/detail_spec.lua @@ -23,7 +23,7 @@ Assert.eq(book.authors, "作者甲、作者乙") Assert.eq(book.intro, "宣传语 & 引言\n\n第一段。\n第二段:完整简介结尾。") Assert.eq(book.cover, wire.artwork) 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(wire, "11", { show_score = false, score = "8.9" }).meta) Assert.is_nil(Mapper.detail(wire, "11", { show_score = true, score = "11" }).meta) @@ -42,7 +42,7 @@ package.loaded["http.request"] = { end, } 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 result, err, calls = nil, nil, 0 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, "取消后迟到的评分不能更新详情") 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"] = { detailAsync = function(id, cb) cb(Mapper.detail(wire, id, grading)); return {} end, } 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.intro, book.intro, "本地上架时没有简介,详情必须补全并落盘") Assert.eq(result.title, "本地书名") Assert.eq(result.category, "本地分类") 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 = "本地分类" })) -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.intro, "自定义简介", "自动补全不能覆盖已编辑的非空字段") -Settings.getSource("ext.zhihu").cookie = nil +Settings.getSource("zhihu").cookie = nil diff --git a/tests/zhihu/login_spec.lua b/tests/zhihu/login_spec.lua index c5d9d01..7259b67 100644 --- a/tests/zhihu/login_spec.lua +++ b/tests/zhihu/login_spec.lua @@ -92,7 +92,7 @@ package.loaded["http.request"] = { } package.loaded["moonsource_zhihu.client"] = nil local Client = require("moonsource_zhihu.client") -local cfg = Settings.getSource("ext.zhihu") +local cfg = Settings.getSource("zhihu") local original_cookie = cfg.cookie cfg.cookie = nil @@ -242,4 +242,4 @@ Assert.is_nil(warnings[#warnings]:find("private-token", 1, true)) Log.warn = original_warn cfg.cookie = original_cookie -Settings.saveSource("ext.zhihu") +Settings.saveSource("zhihu") diff --git a/tests/zhihu/progress_client_spec.lua b/tests/zhihu/progress_client_spec.lua index 12c002e..309bdc8 100644 --- a/tests/zhihu/progress_client_spec.lua +++ b/tests/zhihu/progress_client_spec.lua @@ -9,7 +9,7 @@ local Assert = require("support.assert") local JSON = require("support.json_stub") package.loaded["json"] = JSON 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" local pending, sync_column = {}, false local function request(url, options, cb, body) @@ -104,7 +104,7 @@ local Auth = require("source.auth") Auth.reset() Client.putProgressAsync("2", .4, done) pending[#pending].cb(nil, "HTTP 401", { code = 401 }) -Assert.is_true(Auth.expired("ext.zhihu")) +Assert.is_true(Auth.expired("zhihu")) Auth.reset() cfg.cookie = nil local count = #pending diff --git a/tests/zhihu/progress_spec.lua b/tests/zhihu/progress_spec.lua index 2590446..2c20de4 100644 --- a/tests/zhihu/progress_spec.lua +++ b/tests/zhihu/progress_spec.lua @@ -25,8 +25,8 @@ function Source:loadTocAsync(_identity, cb, force) toc_requests[#toc_requests + 1] = item return { cancel = function() item.cancelled = true end } end -local short = { source_id = "ext.zhihu", stable_id = "1/2" } -local long = { source_id = "ext.zhihu", stable_id = "1" } +local short = { source_id = "zhihu", stable_id = "1/2" } +local long = { source_id = "zhihu", stable_id = "1" } local toc = { { idx = 1, uid = "2", title = "甲" }, { idx = 2, uid = "3", title = "乙" } } local result, err, calls = nil, nil, 0 local function done(value, reason) result, err, calls = value, reason, calls + 1 end diff --git a/tests/zhihu/reviews_spec.lua b/tests/zhihu/reviews_spec.lua index fa003ef..3e1033a 100644 --- a/tests/zhihu/reviews_spec.lua +++ b/tests/zhihu/reviews_spec.lua @@ -8,7 +8,7 @@ local Assert = require("support.assert") local JSON = require("support.json_stub") 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" local pending = {} package.loaded["http.request"] = { @@ -91,7 +91,7 @@ local Auth = require("source.auth") Auth.reset() Client.reviewsAsync("22", 0, false, done) pending[#pending].cb(nil, "HTTP 401", { code = 401 }) -Assert.is_true(Auth.expired("ext.zhihu")) +Assert.is_true(Auth.expired("zhihu")) Auth.reset() local cache_keys = {} @@ -103,7 +103,7 @@ package.loaded["book.review_cache"] = { end, } 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) pending[#pending].cb(JSON.encode(wire())) Assert.len(result, 1) @@ -112,7 +112,7 @@ Assert.eq(result[1].text, "短篇") Assert.eq(result[1].badge, "380") Assert.eq(result[1].heading, "章节评论") 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) cb({ { uid = "22", title = "第一章" }, { uid = "33", title = "第二章" } }) return { cancel = function() error("已完成目录请求不能覆盖当前评论请求") end } diff --git a/tests/zhihu/setting_spec.lua b/tests/zhihu/setting_spec.lua index 5ac61b0..1653832 100644 --- a/tests/zhihu/setting_spec.lua +++ b/tests/zhihu/setting_spec.lua @@ -12,7 +12,7 @@ Themed.install() package.loaded["ui.themes.widgets.row"] = { widget = function(spec) return spec 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.show_paragraph_reviews = nil local checked, allow, reloads = {}, false, 0 @@ -102,7 +102,7 @@ package.loaded["moonsource_zhihu.story"] = { } package.loaded["source.toc"] = { markPaid = function(id, stable_id, uid, value) - Assert.eq(id, "ext.zhihu") + Assert.eq(id, "zhihu") Assert.eq(stable_id, "1/2") Assert.eq(uid, "2") paid = value @@ -110,11 +110,11 @@ package.loaded["source.toc"] = { } local source = require("moonsource_zhihu.source").new() 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(), "设置页和源实例读同一份开关") -require("source.review_setting").set("ext.zhihu", false) +require("source.review_setting").set("zhihu", false) 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 } source:openBookAsync(identity, { chapter_idx = 1 }, function() end) local result, failure @@ -139,7 +139,7 @@ Assert.is_nil(result) Assert.eq(failure, "network down") html, content_error = "

长篇章节

", 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) Assert.eq(content_id, "3/4", "长篇按当前章节请求正文,不把专栏 id 当作节 id") Assert.eq(result.html, require("moonsource_zhihu.content").prepare(html)) @@ -158,4 +158,4 @@ Assert.eq(type(scanned), "function") scanned() Assert.eq(Themed.last("toast").text, "登录成功") Assert.eq(reloads, 3) -Settings.saveSource("ext.zhihu") +Settings.saveSource("zhihu") diff --git a/tests/zhihu/story_spec.lua b/tests/zhihu/story_spec.lua index cf32d2d..57d4a46 100644 --- a/tests/zhihu/story_spec.lua +++ b/tests/zhihu/story_spec.lua @@ -23,7 +23,7 @@ local BookDB = require("book.books_db") local ProgressDB = require("book.progress_db") local NoteDB = require("book.note_db") 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 dest = Paths.bookWorkDir(identity.stable_id, identity.source_id) .. "/book.epub" Assert.is_true(Paths.ensureDir(original:match("(.+)/[^/]+$")))