From 69a72f63c0f37bb591c262fa23cace8385c0cac8 Mon Sep 17 00:00:00 2001 From: Garfield Date: Mon, 30 Nov 2026 21:07:54 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20(search):=20=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E4=B9=A6=E7=9B=AE=E5=B8=A6=E4=B8=8A=E8=AF=91=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../moonsource_weread/mapper.lua | 2 ++ tests/weread/mapper_spec.lua | 13 +++++++++++++ tests/weread/wechat_spec.lua | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/moonsource-weread.koplugin/moonsource_weread/mapper.lua b/moonsource-weread.koplugin/moonsource_weread/mapper.lua index 6ad2012..5e581c1 100644 --- a/moonsource-weread.koplugin/moonsource_weread/mapper.lua +++ b/moonsource-weread.koplugin/moonsource_weread/mapper.lua @@ -355,6 +355,7 @@ end ---@field book_id string ---@field title string ---@field author string +---@field translator string 空串表示接口没给译者 ---@field publisher string --- 搜索 wire → 书目(只留带 bookId 的书,公众号等其它条目没有 bookInfo)。 @@ -369,6 +370,7 @@ function Mapper.searchBooks(data) book_id = tostring(info.bookId), title = info.title or "", author = info.author or "", + translator = type(info.translator) == "string" and info.translator or "", publisher = info.publisher or "", } end diff --git a/tests/weread/mapper_spec.lua b/tests/weread/mapper_spec.lua index 036f645..dcae24e 100644 --- a/tests/weread/mapper_spec.lua +++ b/tests/weread/mapper_spec.lua @@ -14,6 +14,19 @@ package.preload["source.contract"] = nil local Mapper = require("moonsource_weread.mapper") +-- 搜索书目带译者。没有 translator 的书给空串,公众号条目丢掉。 +do + local books = Mapper.searchBooks({ books = { + { type = 0, bookInfo = { bookId = 31503072, title = "地下室手记(果麦经典)", author = "[俄]陀思妥耶夫斯基", translator = "曾思艺" } }, + { type = 0, bookInfo = { bookId = 3300154232, title = "地下室手记(经典译本无删减)", author = "[俄]陀思妥耶夫斯基著" } }, + { type = 3, mpInfo = { title = "公众号" } }, + } }) + Assert.len(books, 2) + Assert.eq(books[1].translator, "曾思艺") + Assert.eq(books[1].author, "[俄]陀思妥耶夫斯基") + Assert.eq(books[2].translator, "", "接口没给译者") +end + do local _b, cover = Mapper.book({ bookId = "wx-2", cover = "https://cdn.weread.qq.com/weread/cover/80/y_1/s_y_1.jpg" }) Assert.eq(cover, "https://cdn.weread.qq.com/weread/cover/80/y_1/t7_y_1.jpg") diff --git a/tests/weread/wechat_spec.lua b/tests/weread/wechat_spec.lua index 6007adc..08d20bd 100644 --- a/tests/weread/wechat_spec.lua +++ b/tests/weread/wechat_spec.lua @@ -1373,7 +1373,7 @@ do fake_client.searchAsync = function(_self, word, cb, author) keyword, got_author = word, author cb({ books = { - { type = 0, bookInfo = { bookId = 834464, title = "活着", author = "余华", publisher = "作家" } }, + { type = 0, bookInfo = { bookId = 834464, title = "活着", author = "余华", translator = "曾思艺", publisher = "作家" } }, { type = 3, mpInfo = { title = "公众号" } }, } }) return { cancel = function() end } @@ -1385,6 +1385,7 @@ do Assert.len(found, 1) Assert.eq(found[1].book_id, "834464") Assert.eq(found[1].author, "余华") + Assert.eq(found[1].translator, "曾思艺", "搜索书目带译者") end -- pushNotesAsync 中途取消:在途请求被取消,迟到回包不回调、不再发后续请求。