rsshub
Version:
Make RSS Great Again!
62 lines (61 loc) • 1.95 kB
JavaScript
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { t as got_default } from "./got-BTowW50G.mjs";
import { load } from "cheerio";
//#region lib/routes/douban/other/replies.ts
const route = {
path: "/replies/:uid",
categories: ["social-media"],
example: "/douban/replies/xiaoyaxiaoya",
parameters: { uid: "用户id,可在用户日记页 URL 中找到" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "日记最新回应",
maintainers: ["nczitzk"],
handler
};
async function handler(ctx) {
const currentUrl = `https://www.douban.com/people/${ctx.req.param("uid")}/notes`;
const $ = load((await got_default({
method: "get",
url: currentUrl
})).data);
const list = $("div.recent-replies-mod ul.comment-list li").toArray().map((item) => {
const p = $(item).find("p");
const match = p.find("a").attr("href").match(/%2Fnote%2F(.*?)%2F%23(.*?)&type=note/);
const nid = match[1];
const cid = match[2];
p.remove();
return { link: `https://www.douban.com/note/${nid}/#${cid}` };
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, (async () => {
const detailResponse = await got_default({
method: "get",
url: item.link
});
const comments = JSON.parse(detailResponse.data.match(/'comments':(.*)\}\],/)[1] + "}]");
while (comments.length > 0) {
const c = comments.shift();
if (c.id === item.link.split("#", 2)[1]) return {
link: item.link,
title: `${c.author.name} 于 ${c.create_time} 的回应`,
pubDate: (/* @__PURE__ */ new Date(c.create_time + " GMT+8")).toUTCString(),
description: c.text,
author: c.author.name
};
if (c.replies.length > 0) comments.push(...c.replies);
}
}))));
return {
title: $("title").text() + " - 最新回应",
link: currentUrl,
item: items
};
}
//#endregion
export { route };