rsshub
Version:
Make RSS Great Again!
67 lines (65 loc) • 2.14 kB
JavaScript
import "./dist-Bog6z_OM.mjs";
import "./config-MQ-7ebJ_.mjs";
import "./logger-C4avouvV.mjs";
import "./ofetch-DKl_Ma9g.mjs";
import { t as parseDate } from "./parse-date-r5WDWHno.mjs";
import "./is-worker-DESPicPc.mjs";
import { t as cache_default } from "./cache-SV6W5EPy.mjs";
import "./helpers-Bo4JQYdN.mjs";
import { t as got_default } from "./got-CO-ndVl2.mjs";
import { t as timezone } from "./timezone-CA9Huotp.mjs";
import { t as rootUrl } from "./utils-Ci1kv7qJ.mjs";
import { load } from "cheerio";
//#region lib/routes/odaily/user.ts
const route = {
path: "/user/:id",
categories: ["new-media"],
example: "/odaily/user/2147486902",
parameters: { id: "用户 id,可在用户页地址栏中找到" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["0daily.com/user/:id", "0daily.com/"] }],
name: "用户文章",
maintainers: ["nczitzk"],
handler
};
async function handler(ctx) {
const id = ctx.req.param("id");
const currentUrl = `${rootUrl}/service/feed_stream/user/${id}?b_id=10&per_page=${ctx.req.query("limit") ?? 25}`;
let author = "";
let items = (await got_default({
method: "get",
url: currentUrl
})).data.data.items.data.map((item) => ({
title: item.title,
summary: item.summary,
link: `${rootUrl}/post/${item.entity_id}`,
pubDate: timezone(parseDate(item.published_at), 8)
}));
items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => {
const detailResponse = await got_default({
method: "get",
url: item.link
});
const content = load(detailResponse.data.match(/"content":"(.*)","extraction_tags":/)[1]);
content("img").each(function() {
content(this).attr("src", content(this).attr("src").replaceAll(String.raw`\"`, ""));
});
item.description = content.html();
item.author = author = detailResponse.data.match(/"name":"(.*)","role_id/)[1];
return item;
})));
return {
title: `${author} - Odaily星球日报`,
link: `${rootUrl}/user/${id}`,
item: items
};
}
//#endregion
export { route };