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,
|
||||
|
||||
@@ -79,6 +79,27 @@ do
|
||||
review = { content = "点评", createTime = 1, author = { name = "甲" } },
|
||||
})
|
||||
Assert.eq(with_replies.replies, 4)
|
||||
Assert.is_nil(with_replies.images)
|
||||
local pictured = Reviews.item({
|
||||
reviewId = "pic", likesCount = 2,
|
||||
review = {
|
||||
content = "带图", createTime = 3, author = { name = "甲" },
|
||||
pictures = {
|
||||
{ url = "https://weread-picture.example/a.png", width = 800, height = 1067 },
|
||||
{ url = "", width = 1, height = 1 },
|
||||
},
|
||||
},
|
||||
})
|
||||
Assert.len(pictured.images, 1)
|
||||
Assert.eq(pictured.images[1].url, "https://weread-picture.example/a.png")
|
||||
Assert.eq(pictured.images[1].width, 800)
|
||||
Assert.eq(pictured.images[1].height, 1067)
|
||||
Assert.eq(pictured.images[1].headers.Referer, "https://weread.qq.com/")
|
||||
local reply = Reviews.commentItem({
|
||||
commentId = "c", content = "回复", createTime = 4, author = { name = "乙" },
|
||||
pictures = { { url = "https://weread-picture.example/b.png", width = 40, height = 40 } },
|
||||
})
|
||||
Assert.eq(reply.images[1].url, "https://weread-picture.example/b.png")
|
||||
end
|
||||
|
||||
do -- 想法下的评论页:楼中楼只记被回复者;空列表但声称有条数是失败;游标不前进就停
|
||||
|
||||
Reference in new issue
Block a user