rsshub
Version:
Make RSS Great Again!
115 lines (114 loc) • 4.14 kB
JavaScript
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs";
import { t as got_default } from "./got-BTowW50G.mjs";
import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime";
import { renderToString } from "hono/jsx/dom/server";
import { raw } from "hono/html";
//#region lib/routes/dedao/user.tsx
const types = {
0: "动态",
7: "书评",
12: "视频"
};
const mentionPattern = /<\u{2267}\u{2746}>\{"name":"(.*?)","uid":"\d+","at":"1"\}<\/\u{2266}\u{2746}>/gu;
const formatNoteText = (text = "") => text.replaceAll("\n\n", "</p><p>").replaceAll(mentionPattern, " @$1");
const extractImageUrl = (value) => value?.match(/"url":"(.*?)"/)?.[1];
const route = {
path: "/user/:id/:type?",
categories: ["new-media"],
example: "/dedao/user/VkA5OqLX4RyGxmZRNBMlwBrDaJQ9og",
parameters: {
id: "用户 id,可在对应用户主页 URL 中找到",
type: "类型,见下表,默认为`0`,即动态"
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "用户主页",
maintainers: ["nczitzk"],
handler,
description: `| 动态 | 书评 | 视频 |
| ---- | ---- | ---- |
| 0 | 7 | 12 |`
};
async function handler(ctx) {
const id = ctx.req.param("id") ?? "";
const type = ctx.req.param("type") ? Number.parseInt(ctx.req.param("type")) : 0;
const count = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 100;
const rootUrl = "https://m.igetget.com";
const currentUrl = `${rootUrl}/native/mine/account#/user/detail?enId=${id}`;
const apiUrl = `${rootUrl}/native/api/homePage/topicNote`;
const data = (await got_default({
method: "post",
url: `${rootUrl}/native/api/homePage/userInfo`,
json: { hazy: id }
})).data;
const author = data.c.nickname;
const image = data.c.avatar;
const description = `${data.c.v_info}: ${data.c.slogan}`;
const items = (await got_default({
method: "post",
url: apiUrl,
json: {
uid: null,
max_id_str: "0",
count,
max_createtime: 0,
is_only_repost: 0,
load_chain: true,
load_tag: 1,
source: 0,
note_type: type,
only_origin: false,
with_highlight: true,
hazy: id
}
})).data.c.list.map((item) => ({
author,
title: item.content || item.note || item.extra.title,
link: item.share_url,
pubDate: parseDate(item.create_time * 1e3),
description: renderToString(/* @__PURE__ */ jsxs(Fragment, { children: [
item.origin_notes_owner.name ? /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx("p", { children: raw(formatNoteText(item.content)) }),
/* @__PURE__ */ jsx("br", {}),
/* @__PURE__ */ jsxs("p", { children: [
"引用 ",
item.origin_notes_owner.name,
item.origin_notes_owner.Vinfo ? ` (${item.origin_notes_owner.Vinfo})` : "",
":"
] })
] }) : null,
/* @__PURE__ */ jsx("p", { children: raw(formatNoteText(item.note)) }),
item.extra ? /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx("br", {}),
item.extra.img ? item.extra.share_ext ? /* @__PURE__ */ jsx("a", {
href: item.extra.share_ext.h_5_url,
children: /* @__PURE__ */ jsxs("figure", { children: [/* @__PURE__ */ jsx("img", { src: item.extra.img }), /* @__PURE__ */ jsx("figcaption", { children: item.extra.title })] })
}) : /* @__PURE__ */ jsxs("figure", { children: [/* @__PURE__ */ jsx("img", { src: item.extra.img }), /* @__PURE__ */ jsx("figcaption", { children: item.extra.title })] }) : null,
item.extra.images ? item.extra.images.map((image) => {
const imageUrl = extractImageUrl(image);
return imageUrl ? /* @__PURE__ */ jsx("img", { src: imageUrl }) : null;
}) : null,
item.video.video_cover ? (() => {
const imageUrl = extractImageUrl(item.video.video_cover);
return imageUrl ? /* @__PURE__ */ jsx("figure", { children: /* @__PURE__ */ jsx("img", { src: imageUrl }) }) : null;
})() : null
] }) : null
] }))
}));
return {
title: `${author}的得到主页 - ${types[type]}`,
link: currentUrl,
item: items,
image,
description,
allowEmpty: true
};
}
//#endregion
export { route };