rsshub
Version:
Make RSS Great Again!
116 lines (114 loc) • 3.9 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import "./md5-C8GRvctM.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { n as header, r as processImage, t as getSignedHeader } from "./utils-Vxf_K345.mjs";
//#region lib/routes/zhihu/topic.ts
const route = {
path: "/topic/:topicId/:isTop?",
categories: ["social-media"],
example: "/zhihu/topic/19828946",
parameters: {
topicId: "话题 id",
isTop: "仅精华,默认为否,其他值为是"
},
features: {
requireConfig: [{
name: "ZHIHU_COOKIES",
description: ""
}],
requirePuppeteer: false,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["www.zhihu.com/topic/:topicId/:type"],
target: "/topic/:topicId"
}],
name: "话题",
maintainers: ["xyqfer"],
handler
};
async function handler(ctx) {
const { topicId, isTop = false } = ctx.req.param();
const link = `https://www.zhihu.com/topic/${topicId}/${isTop ? "top-answers" : "newest"}`;
const topicMeta = await cache_default.tryGet(`zhihu:topic:${topicId}`, async () => {
const url = `https://www.zhihu.com/topic/${topicId}`;
const apiPath$1 = `/api/v4/topics/${topicId}/intro?include=content.meta.content.photos`;
const signedHeader$1 = await getSignedHeader(url, apiPath$1);
const { data: response$1 } = await got_default("https://www.zhihu.com" + apiPath$1, { headers: signedHeader$1 });
return response$1;
});
const apiPath = `/api/v5.1/topics/${topicId}/feeds/${isTop ? "top_activity" : "timeline_activity"}`;
const signedHeader = await getSignedHeader(link, apiPath);
const { data: response } = await got_default(`https://www.zhihu.com${apiPath}`, { headers: {
...header,
...signedHeader,
Referer: link
} });
const items = response.data.map(({ target: item }) => {
const type = item.type;
let title = "";
let description = "";
let link$1 = "";
let pubDate;
let author = "";
switch (type) {
case "answer":
title = `${item.question.title}-${item.author.name}的回答:${item.excerpt}`;
description = `<strong>${item.question.title}</strong><br>${item.author.name}的回答<br/>${processImage(item.content)}`;
link$1 = `https://www.zhihu.com/question/${item.question.id}/answer/${item.id}`;
pubDate = parseDate(item.updated_time * 1e3);
author = item.author.name;
break;
case "question":
title = item.title;
description = item.title;
link$1 = `https://www.zhihu.com/question/${item.id}`;
pubDate = parseDate(item.created * 1e3);
break;
case "article":
title = item.title;
description = processImage(item.content);
link$1 = item.url;
pubDate = parseDate(item.created * 1e3);
break;
case "zvideo":
title = item.title;
description = `${item.description}<br>
<video controls poster="${item.video.thumbnail}" preload="metadata">
<source src="${item.video.playlist.fhd?.url ?? item.video.playlist.hd?.url ?? item.video.playlist.ld?.url ?? item.video.playlist.sd?.url}" type="video/mp4">
</video>`;
link$1 = item.url;
pubDate = parseDate(item.created_at * 1e3);
break;
default:
description = "未知类型,请点击<a href=\"https://github.com/DIYgod/RSSHub/issues\">链接</a>提交issue";
pubDate = parseDate(Date.now());
}
return {
title,
description,
author,
pubDate,
guid: item.id.toString(),
link: link$1
};
});
return {
title: `知乎话题-${topicId}-${isTop ? "精华" : "讨论"}`,
description: topicMeta.content.introduction,
link,
item: items
};
}
//#endregion
export { route };