✨ (search): 搜索书目带上译者

This commit is contained in:
Garfield committed 2026-11-30 21:07:54 +08:00
1 parent fb35a0560d
commit 69a72f63c0
3 files changed
+17 -1

No files matched your search

@@ -355,6 +355,7 @@ end
---@field book_id string ---@field book_id string
---@field title string ---@field title string
---@field author string ---@field author string
---@field translator string 空串表示接口没给译者
---@field publisher string ---@field publisher string
--- 搜索 wire → 书目(只留带 bookId 的书,公众号等其它条目没有 bookInfo)。 --- 搜索 wire → 书目(只留带 bookId 的书,公众号等其它条目没有 bookInfo)。
@@ -369,6 +370,7 @@ function Mapper.searchBooks(data)
book_id = tostring(info.bookId), book_id = tostring(info.bookId),
title = info.title or "", title = info.title or "",
author = info.author or "", author = info.author or "",
translator = type(info.translator) == "string" and info.translator or "",
publisher = info.publisher or "", publisher = info.publisher or "",
} }
end end
+13
View File
@@ -14,6 +14,19 @@ package.preload["source.contract"] = nil
local Mapper = require("moonsource_weread.mapper") 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 do
local _b, cover = Mapper.book({ bookId = "wx-2", cover = "https://cdn.weread.qq.com/weread/cover/80/y_1/s_y_1.jpg" }) 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") Assert.eq(cover, "https://cdn.weread.qq.com/weread/cover/80/y_1/t7_y_1.jpg")
+2 -1
View File
@@ -1373,7 +1373,7 @@ do
fake_client.searchAsync = function(_self, word, cb, author) fake_client.searchAsync = function(_self, word, cb, author)
keyword, got_author = word, author keyword, got_author = word, author
cb({ books = { cb({ books = {
{ type = 0, bookInfo = { bookId = 834464, title = "活着", author = "余华", publisher = "作家" } }, { type = 0, bookInfo = { bookId = 834464, title = "活着", author = "余华", translator = "曾思艺", publisher = "作家" } },
{ type = 3, mpInfo = { title = "公众号" } }, { type = 3, mpInfo = { title = "公众号" } },
} }) } })
return { cancel = function() end } return { cancel = function() end }
@@ -1385,6 +1385,7 @@ do
Assert.len(found, 1) Assert.len(found, 1)
Assert.eq(found[1].book_id, "834464") Assert.eq(found[1].book_id, "834464")
Assert.eq(found[1].author, "余华") Assert.eq(found[1].author, "余华")
Assert.eq(found[1].translator, "曾思艺", "搜索书目带译者")
end end
-- pushNotesAsync 中途取消:在途请求被取消,迟到回包不回调、不再发后续请求。 -- pushNotesAsync 中途取消:在途请求被取消,迟到回包不回调、不再发后续请求。