From a890c230ac40564436f4d2dc77a3450fa27a483c Mon Sep 17 00:00:00 2001 From: Garfield Date: Thu, 26 Nov 2026 15:52:52 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20(search):=20=E4=B9=A6=E7=9B=AE?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=B8=A6=E4=B8=8A=E4=BD=9C=E8=80=85=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /store/search 的 author 不再写死为空。不传时仍是空串。 --- moonsource-weread.koplugin/moonsource_weread/client.lua | 5 +++-- moonsource-weread.koplugin/moonsource_weread/source.lua | 7 ++++--- tests/weread/client_spec.lua | 4 ++++ tests/weread/wechat_spec.lua | 9 +++++---- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/moonsource-weread.koplugin/moonsource_weread/client.lua b/moonsource-weread.koplugin/moonsource_weread/client.lua index 8f03baf..7dd4d88 100644 --- a/moonsource-weread.koplugin/moonsource_weread/client.lua +++ b/moonsource-weread.koplugin/moonsource_weread/client.lua @@ -72,11 +72,12 @@ end --- 书城搜索(App ``GET /store/search``)。回包书在 ``data[]``,每条 ``bookInfo``;补成 ``books[]`` 交给 mapper。 ---@param keyword string ---@param cb fun(data: table|nil, err: string|nil) +---@param author string|nil 作者过滤;旧调用不传,查询里仍是空串 ---@return { cancel: fun() }|nil -function Client:searchAsync(keyword, cb) +function Client:searchAsync(keyword, cb, author) return Eink.callAsync("GET", "/store/search", { query = { - keyword = keyword, author = "", authorVids = "", categoryId = "", + keyword = keyword, author = type(author) == "string" and author or "", authorVids = "", categoryId = "", count = 20, maxIdx = 0, type = 0, v = 2, outer = 0, fromBookId = "", scope = 0, scene = 0, filterType = 0, filterField = "", queryUid = "", isQueryWord = 0, }, diff --git a/moonsource-weread.koplugin/moonsource_weread/source.lua b/moonsource-weread.koplugin/moonsource_weread/source.lua index 7a49573..8829576 100644 --- a/moonsource-weread.koplugin/moonsource_weread/source.lua +++ b/moonsource-weread.koplugin/moonsource_weread/source.lua @@ -1520,18 +1520,19 @@ function Source:paragraphReviewsEnabled() return require("source.review_setting").enabled(self.id) end ---- 按书名搜索微信读书书目(关联本地书看段评用)。 +--- 按书名搜索微信读书书目(关联本地书看段评用)。author 写入 /store/search 的作者参数。 ---@param keyword string ---@param cb fun(books: WechatSearchBook[]|nil, err: string|nil) +---@param author string|nil ---@return { cancel: fun() }|nil -function Source:searchBooksAsync(keyword, cb) +function Source:searchBooksAsync(keyword, cb, author) return self._client:searchAsync(keyword, function(wire, err) if not wire then cb(nil, err) return end cb(Mapper.searchBooks(wire)) - end) + end, author) end --- 书城搜索:回包形状同 listStoreAsync。 diff --git a/tests/weread/client_spec.lua b/tests/weread/client_spec.lua index 138391c..71e7e12 100644 --- a/tests/weread/client_spec.lua +++ b/tests/weread/client_spec.lua @@ -214,7 +214,11 @@ do req = call(client.searchAsync, client, "三体", function(d) wire = d end) Assert.eq(req.path, "/store/search") Assert.eq(req.query.keyword, "三体") + Assert.eq(req.query.author, "") Assert.eq(req.query.v, 2) + req = call(client.searchAsync, client, "三体", function() end, "刘慈欣") + Assert.eq(req.query.keyword, "三体") + Assert.eq(req.query.author, "刘慈欣") Assert.eq(req.query.type, 0) Assert.eq(wire.books[1].bookInfo.bookId, "9") end diff --git a/tests/weread/wechat_spec.lua b/tests/weread/wechat_spec.lua index b77998a..6007adc 100644 --- a/tests/weread/wechat_spec.lua +++ b/tests/weread/wechat_spec.lua @@ -1369,9 +1369,9 @@ do require("moonsource_weread.toc").clear() -- 书名搜索:只留带 bookId 的书目。 - local keyword - fake_client.searchAsync = function(_self, word, cb) - keyword = word + local keyword, got_author + fake_client.searchAsync = function(_self, word, cb, author) + keyword, got_author = word, author cb({ books = { { type = 0, bookInfo = { bookId = 834464, title = "活着", author = "余华", publisher = "作家" } }, { type = 3, mpInfo = { title = "公众号" } }, @@ -1379,8 +1379,9 @@ do return { cancel = function() end } end local found - src:searchBooksAsync("活着", function(books) found = books end) + src:searchBooksAsync("活着", function(books) found = books end, "余华") Assert.eq(keyword, "活着") + Assert.eq(got_author, "余华") Assert.len(found, 1) Assert.eq(found[1].book_id, "834464") Assert.eq(found[1].author, "余华")