🐛 (reviews): 评论配图带上微信阅读来源

空地址丢掉。没有图时不给出图片列表。

关联 #148
This commit is contained in:
Garfield committed 2026-11-26 16:55:31 +08:00
1 parent a890c230ac
commit 7b3eeb8fe6
2 files changed
+47

No files matched your search

@@ -87,6 +87,30 @@ function Reviews.locate(hotspots, html)
return out
end
local PICTURE_HEADERS = { Referer = "https://weread.qq.com/" }
--- 评论配图。没有图时 nil,空数组不当成有图。
---@param review table|nil
---@return { url: string, width: integer|nil, height: integer|nil, headers: table }[]|nil
local function imagesOf(review)
local pics = type(review) == "table" and review.pictures or nil
if type(pics) ~= "table" then return nil end
local images = {}
for _idx, pic in ipairs(pics) do
local url = type(pic) == "table" and pic.url or nil
if type(url) == "string" and url ~= "" then
images[#images + 1] = {
url = url,
width = tonumber(pic.width),
height = tonumber(pic.height),
headers = PICTURE_HEADERS,
}
end
end
if #images == 0 then return nil end
return images
end
--- 单条 pageReviews → 展示项。
---@param entry table
---@return WechatReview
@@ -96,6 +120,7 @@ function Reviews.item(entry)
id = entry.reviewId,
author = type(review.author) == "table" and review.author.name or "",
content = review.content,
images = imagesOf(review) or imagesOf(entry),
likes = tonumber(entry.likesCount) or 0,
replies = tonumber(entry.commentsCount) or tonumber(review.commentsCount) or 0,
time = tonumber(review.createTime) or 0,
@@ -114,6 +139,7 @@ function Reviews.commentItem(entry)
id = tostring(entry.commentId or comment.commentId or ""),
author = type(author) == "table" and author.name or "",
content = tostring(comment.content or entry.content or ""),
images = imagesOf(comment) or imagesOf(entry),
likes = tonumber(entry.likesCount or comment.likesCount) or 0,
replies = 0,
reply_to = type(reply_user) == "table" and reply_user.name or nil,