rsshub
Version:
Make RSS Great Again!
86 lines (84 loc) • 3.27 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import { t as config } from "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.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 } from "./utils-Vxf_K345.mjs";
//#region lib/routes/zhihu/all-collections.ts
const route = {
path: "/people/allCollections/:id",
categories: ["social-media"],
view: ViewType.Articles,
example: "/zhihu/people/allCollections/87-44-49-67",
parameters: { id: "作者 id,可在用户主页 URL 中找到" },
features: {
requireConfig: [{
name: "ZHIHU_COOKIES",
description: ""
}],
requirePuppeteer: false,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["www.zhihu.com/people/:id"] }],
name: "用户全部收藏内容",
maintainers: ["Healthyyue"],
handler
};
async function handler(ctx) {
const id = ctx.req.param("id");
const collections = (await got_default(`https://api.zhihu.com/people/${id}/collections`, { headers: {
cookie: config.zhihu.cookies,
Referer: `https://www.zhihu.com/people/${id}/collections`
} })).data.data;
const items = (await Promise.all(collections.map(async (collection) => {
const { data: items$1, paging: { totals } } = (await got_default(`https://www.zhihu.com/api/v4/collections/${collection.id}/items?offset=0&limit=20`, { headers: {
...header,
cookie: config.zhihu.cookies,
Referer: `https://www.zhihu.com/collection/${collection.id}`
} })).data;
if (totals > 20) {
const offsetList = Array.from({ length: Math.ceil(totals / 20) - 1 }, (_, index) => (index + 1) * 20);
const otherPages = await Promise.all(offsetList.map((offset) => cache_default.tryGet(`https://www.zhihu.com/api/v4/collections/${collection.id}/items?offset=${offset}&limit=20`, async () => {
return (await got_default(`https://www.zhihu.com/api/v4/collections/${collection.id}/items?offset=${offset}&limit=20`, { headers: {
...header,
cookie: config.zhihu.cookies,
Referer: `https://www.zhihu.com/collection/${collection.id}`
} })).data.data;
})));
items$1.push(...otherPages.flat());
}
return {
collectionId: collection.id,
collectionTitle: collection.title,
items: items$1
};
}))).flatMap((collection) => collection.items.map((item) => ({
...item,
collectionTitle: collection.collectionTitle
})));
return {
title: `${collections[0].creator.name}的知乎收藏`,
link: `https://www.zhihu.com/people/${id}/collections`,
item: items.map((item) => {
const content = item.content;
return {
title: content.type === "article" || content.type === "zvideo" ? content.title : content.question.title,
link: content.url,
description: content.type === "zvideo" ? `<img src=${content.video.url}/>` : content.content,
pubDate: parseDate((content.type === "article" ? content.updated : content.updated_time) * 1e3),
category: [item.collectionTitle]
};
})
};
}
//#endregion
export { route };