From b45d47aea5527cc0eea662e309ad9a66572f501d 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_xiaoxiang/_meta.lua | 2 +- .../moonsource_xiaoxiang/client.lua | 4 +- .../moonsource_xiaoxiang/mapper.lua | 2 +- .../moonsource_xiaoxiang/setting.lua | 2 +- tests/xiaoxiang/changpei_xiaoxiang_spec.lua | 56 +++++++++---------- tests/xiaoxiang/client_spec.lua | 6 +- tests/xiaoxiang/progress_spec.lua | 2 +- tests/xiaoxiang/setting_spec.lua | 2 +- 8 files changed, 38 insertions(+), 38 deletions(-) diff --git a/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/_meta.lua b/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/_meta.lua index 4ac74ba..f9c7d9c 100644 --- a/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/_meta.lua +++ b/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/_meta.lua @@ -7,7 +7,7 @@ local _ = require("l10n").get("moonsource_xiaoxiang") return { - id = "ext.xiaoxiang", + id = "xiaoxiang", name = _("潇湘书院"), type = "chapter", description = _("潇湘书院书架与在线阅读"), diff --git a/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/client.lua b/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/client.lua index 3a45374..362bee1 100644 --- a/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/client.lua +++ b/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/client.lua @@ -22,7 +22,7 @@ local Client = {} --- 已保存的登录 Cookie。 ---@return string|nil function Client.cookie() - local cookie = require("utils.settings").getSource("ext.xiaoxiang").cookie + local cookie = require("utils.settings").getSource("xiaoxiang").cookie return type(cookie) == "string" and cookie ~= "" and cookie or nil end @@ -42,7 +42,7 @@ local function page(url, cb) end) end -local SOURCE_ID = "ext.xiaoxiang" +local SOURCE_ID = "xiaoxiang" local API = "https://www.xxsypro.com/api" --- 请求头里的 Cookie:没有 csrfToken 就补一个,网页端要求 Cookie 与 `_csrfToken` 同值。 diff --git a/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/mapper.lua b/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/mapper.lua index 92f1827..a734864 100644 --- a/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/mapper.lua +++ b/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/mapper.lua @@ -10,7 +10,7 @@ local _ = require("l10n").get("moonsource_xiaoxiang") local Mapper = {} -local SOURCE_ID = "ext.xiaoxiang" +local SOURCE_ID = "xiaoxiang" --- 新站 JSON 的整数身份不能经过 Lua number;不匹配小数、指数或字符串里的转义引号。 function Mapper.decode(raw) diff --git a/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/setting.lua b/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/setting.lua index 0e28509..02684ec 100644 --- a/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/setting.lua +++ b/moonsource-xiaoxiang.koplugin/moonsource_xiaoxiang/setting.lua @@ -10,7 +10,7 @@ local _ = require("l10n").get("moonsource_xiaoxiang") local CookieLogin = require("source.cookie_login") -local SOURCE_ID = "ext.xiaoxiang" +local SOURCE_ID = "xiaoxiang" local Setting = {} ---@return boolean diff --git a/tests/xiaoxiang/changpei_xiaoxiang_spec.lua b/tests/xiaoxiang/changpei_xiaoxiang_spec.lua index cf87738..204bdd6 100644 --- a/tests/xiaoxiang/changpei_xiaoxiang_spec.lua +++ b/tests/xiaoxiang/changpei_xiaoxiang_spec.lua @@ -159,16 +159,16 @@ do end package.loaded["moonsource_xiaoxiang.client"] = nil local Settings = require("utils.settings") - local cfg = Settings.getSource("ext.xiaoxiang") + local cfg = Settings.getSource("xiaoxiang") cfg.cookie = "csrfToken=C1; ywKey=K" - Settings.saveSource("ext.xiaoxiang", cfg) + Settings.saveSource("xiaoxiang", cfg) local Client = require("moonsource_xiaoxiang.client") require("source.auth").reset() seen.reply = '{"code":0,"data":{"isLogin":0}}' local err Client.shelfRemoveAsync("35554414603847007", function(_wire, e) err = e end) - Assert.is_true(require("source.auth").expired("ext.xiaoxiang")) + Assert.is_true(require("source.auth").expired("xiaoxiang")) Assert.is_nil(seen.post_url) seen.reply = '{"code":0,"data":{"isLogin":1,"user":{"guid":"42"}}}' @@ -210,7 +210,7 @@ do Assert.is_true(ok) Assert.eq(n, 1, "校验结果复用") cfg.cookie = "csrfToken=C2; ywKey=K2" - Settings.saveSource("ext.xiaoxiang", cfg) + Settings.saveSource("xiaoxiang", cfg) Client.shelfRemoveAsync("35554414603847007", function(wire) ok = wire ~= nil end) Assert.eq(n, 2, "换了 Cookie 重新校验") Client.AUTH_TTL = 0 @@ -231,7 +231,7 @@ do .. '"fontResponse":{"fixedFontTtf":"https://cdn.test/f.ttf"}}]}}' replies[1] = "Not Found" cfg.cookie = "csrfToken=C1; ywKey=K; ywGuid=42" - Settings.saveSource("ext.xiaoxiang", cfg) + Settings.saveSource("xiaoxiang", cfg) local fock_called = false package.loaded["moonsource_xiaoxiang.fock"] = { chapterAsync = function() fock_called = true; return { cancel = function() end } end } local ferr @@ -242,7 +242,7 @@ do Assert.is_false(fock_called, "坏字体不进解密") package.loaded["moonsource_xiaoxiang.fock"] = nil cfg.cookie = nil - Settings.saveSource("ext.xiaoxiang", cfg) + Settings.saveSource("xiaoxiang", cfg) package.loaded["moonsource_xiaoxiang.client"] = nil end @@ -252,18 +252,18 @@ do Assert.eq(CpSetting.parseCookie(" "), "") local Settings = require("utils.settings") local Auth = require("source.auth") - local cfg = Settings.getSource("ext.changpei") + local cfg = Settings.getSource("changpei") Auth.reset() cfg.cookie = nil - Settings.saveSource("ext.changpei", cfg) + Settings.saveSource("changpei", cfg) Assert.eq(#CpSetting.rows(), 4, "未登录:账号 + 浏览器 + 粘贴 + 章评") cfg.cookie = "PHPSESSID=T1" - Settings.saveSource("ext.changpei", cfg) + Settings.saveSource("changpei", cfg) Assert.eq(#CpSetting.rows(), 5, "已登录:账号 + 浏览器 + 粘贴 + 退出 + 章评") - Auth.expire("ext.changpei", "x") + Auth.expire("changpei", "x") Assert.eq(#CpSetting.rows(), 5, "失效后仍保留浏览器与粘贴入口") cfg.cookie = nil - Settings.saveSource("ext.changpei", cfg) + Settings.saveSource("changpei", cfg) Auth.reset() local XxSetting = require("moonsource_xiaoxiang.setting") @@ -279,9 +279,9 @@ do end package.loaded["moonsource_changpei.client"] = nil local Settings = require("utils.settings") - local cfg = Settings.getSource("ext.changpei") + local cfg = Settings.getSource("changpei") cfg.cookie = "PHPSESSID=T1" - Settings.saveSource("ext.changpei", cfg) + Settings.saveSource("changpei", cfg) local Client = require("moonsource_changpei.client") local Auth = require("source.auth") Auth.reset() @@ -290,13 +290,13 @@ do Assert.eq(seen.cookie, "PHPSESSID=T1") Assert.eq(seen.headers.Client, "pc") Assert.matches(err, "扫码登录") - Assert.is_true(Auth.expired("ext.changpei")) + Assert.is_true(Auth.expired("changpei")) cfg.cookie = nil - Settings.saveSource("ext.changpei", cfg) + Settings.saveSource("changpei", cfg) Auth.reset() Client.searchAsync("x", function() end) Assert.is_nil(seen.cookie) - Assert.is_true(not Auth.expired("ext.changpei")) + Assert.is_true(not Auth.expired("changpei")) package.preload["http.request"] = nil end @@ -416,7 +416,7 @@ do local Client = require("moonsource_changpei.client") local Auth = require("source.auth") local settings = require("utils.settings") - settings.saveSource("ext.changpei", { cookie = "PHPSESSID=a; _c_n_=dev; moon_token=OLD; moon_refresh=RF" }) + settings.saveSource("changpei", { cookie = "PHPSESSID=a; _c_n_=dev; moon_token=OLD; moon_refresh=RF" }) Auth.reset() local wire @@ -424,25 +424,25 @@ do Assert.not_nil(wire) Assert.eq(renew_calls, 1) Assert.eq(tokens[#tokens], "NEW1") - Assert.matches(settings.getSource("ext.changpei").cookie, "moon_token=NEW1") - Assert.matches(settings.getSource("ext.changpei").cookie, "moon_refresh=RF") - Assert.is_false(Auth.expired("ext.changpei")) + Assert.matches(settings.getSource("changpei").cookie, "moon_token=NEW1") + Assert.matches(settings.getSource("changpei").cookie, "moon_refresh=RF") + Assert.is_false(Auth.expired("changpei")) - settings.saveSource("ext.changpei", { cookie = "PHPSESSID=a; _c_n_=dev; moon_token=OLD; moon_refresh=RF" }) + settings.saveSource("changpei", { cookie = "PHPSESSID=a; _c_n_=dev; moon_token=OLD; moon_refresh=RF" }) grpc_status = "16" local failed Client.historyAsync(function(w, err) failed = { w, err } end) Assert.is_nil(failed[1]) Assert.matches(failed[2], "moon%-cookie%-storage") - Assert.is_true(Auth.expired("ext.changpei")) + Assert.is_true(Auth.expired("changpei")) - settings.saveSource("ext.changpei", { cookie = "PHPSESSID=a; _c_n_=dev; moon_token=OLD" }) + settings.saveSource("changpei", { cookie = "PHPSESSID=a; _c_n_=dev; moon_token=OLD" }) Auth.reset() renew_calls = 0 Client.historyAsync(function() end) Assert.eq(renew_calls, 0, "没有 refresh_token 不请求") - Assert.is_true(Auth.expired("ext.changpei")) - settings.saveSource("ext.changpei", {}) + Assert.is_true(Auth.expired("changpei")) + settings.saveSource("changpei", {}) Auth.reset() package.preload["http.request"] = nil end @@ -523,9 +523,9 @@ do } end local Settings = require("utils.settings") - local cfg = Settings.getSource("ext.xiaoxiang") + local cfg = Settings.getSource("xiaoxiang") cfg.cookie = "csrfToken=C1; ywKey=K" - Settings.saveSource("ext.xiaoxiang", cfg) + Settings.saveSource("xiaoxiang", cfg) package.loaded["moonsource_xiaoxiang.client"] = nil local Deep = require("moonsource_xiaoxiang.client") require("source.auth").reset() @@ -535,7 +535,7 @@ do Assert.len(rows, 60) Assert.eq(pages, 60) cfg.cookie = nil - Settings.saveSource("ext.xiaoxiang", cfg) + Settings.saveSource("xiaoxiang", cfg) package.loaded["moonsource_xiaoxiang.client"] = nil package.preload["http.request"] = nil end diff --git a/tests/xiaoxiang/client_spec.lua b/tests/xiaoxiang/client_spec.lua index b1f02ef..0f7a9fd 100644 --- a/tests/xiaoxiang/client_spec.lua +++ b/tests/xiaoxiang/client_spec.lua @@ -44,17 +44,17 @@ network = "failure" C.shelfAsync(function(value, reason) result, err = value, reason end) A.is_nil(result) A.eq(err, "timeout") -A.is_false(Auth.expired("ext.xiaoxiang"), "暂时网络失败保留登录") +A.is_false(Auth.expired("xiaoxiang"), "暂时网络失败保留登录") network = "expired" C.shelfAsync(function(value, reason) result, err = value, reason end) -A.is_true(Auth.expired("ext.xiaoxiang")) +A.is_true(Auth.expired("xiaoxiang")) A.eq(posts, 0) Auth.reset() network = "wait" C.shelfAsync(function(value, reason) result, err = value, reason end) cfg.cookie = "csrfToken=new; ywguid=43" pending('{"code":0,"data":{"isLogin":0}}') -A.is_false(Auth.expired("ext.xiaoxiang"), "旧请求不能注销新账号") +A.is_false(Auth.expired("xiaoxiang"), "旧请求不能注销新账号") A.eq(err, "账号已变化,请重新登录") cfg.cookie = "csrfToken=x%26; ywguid=42" network, cancelled, info = "wait", false, nil diff --git a/tests/xiaoxiang/progress_spec.lua b/tests/xiaoxiang/progress_spec.lua index 76580b0..ad3dee5 100644 --- a/tests/xiaoxiang/progress_spec.lua +++ b/tests/xiaoxiang/progress_spec.lua @@ -28,7 +28,7 @@ function source:loadTocAsync(_identity, cb) if not delayed then cb(toc) end return { cancel = function() stopped = true end } end -local identity = { source_id = "ext.xiaoxiang", stable_id = "123" } +local identity = { source_id = "xiaoxiang", stable_id = "123" } local result, err source:getProgressAsync(identity, function(data) result = data end) A.eq(result.chapter_idx, 2) diff --git a/tests/xiaoxiang/setting_spec.lua b/tests/xiaoxiang/setting_spec.lua index d545173..e08f71e 100644 --- a/tests/xiaoxiang/setting_spec.lua +++ b/tests/xiaoxiang/setting_spec.lua @@ -24,7 +24,7 @@ end package.preload["reader.session"] = function() return { current = function() return nil end } end package.preload["book.books_db"] = function() return { prepareAccountSync = function(id, shelf_add) - Assert.eq(id, "ext.xiaoxiang") + Assert.eq(id, "xiaoxiang") Assert.is_true(shelf_add) Assert.eq(cfg.cookie, "session=old") prepared = prepared + 1