rsshub
Version:
Make RSS Great Again!
162 lines (160 loc) • 6.69 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 { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import "./proxy-Db7uGcYb.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import "./puppeteer-DGmvuGvT.mjs";
import { n as queryToBoolean, t as fallback } from "./readable-social-DoIL4WB3.mjs";
import "./puppeteer-utils-BK3JC9qW.mjs";
import { t as utils_default } from "./utils-D1eKDLN1.mjs";
import querystring from "node:querystring";
//#region lib/routes/weibo/user.ts
const route = {
path: "/user/:uid/:routeParams?",
categories: ["social-media"],
view: ViewType.SocialMedia,
example: "/weibo/user/1195230310",
parameters: {
uid: "用户 id, 博主主页打开控制台执行 `$CONFIG.oid` 获取",
routeParams: "额外参数;请参阅上面的说明和表格;特别地,当 `routeParams=1` 时开启微博视频显示"
},
features: {
requireConfig: [{
name: "WEIBO_COOKIES",
optional: true,
description: ""
}],
requirePuppeteer: true,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [
{
source: ["m.weibo.cn/u/:uid", "m.weibo.cn/profile/:uid"],
target: "/user/:uid"
},
{
source: ["weibo.com/u/:uid"],
target: "/user/:uid"
},
{
source: ["www.weibo.com/u/:uid"],
target: "/user/:uid"
}
],
name: "博主",
maintainers: [
"DIYgod",
"iplusx",
"Rongronggg9",
"Konano"
],
handler,
description: `::: warning
部分博主仅登录可见,未提供 Cookie 的情况下不支持订阅,可以通过打开 \`https://m.weibo.cn/u/:uid\` 验证
:::`
};
async function handler(ctx) {
const uid = ctx.req.param("uid");
let displayVideo = "1";
let displayArticle = "0";
let displayComments = "0";
let showRetweeted = "1";
let showBloggerIcons = "0";
if (ctx.req.param("routeParams")) if (ctx.req.param("routeParams") === "1" || ctx.req.param("routeParams") === "0") displayVideo = ctx.req.param("routeParams");
else {
const routeParams = querystring.parse(ctx.req.param("routeParams"));
displayVideo = fallback(void 0, queryToBoolean(routeParams.displayVideo), true) ? "1" : "0";
displayArticle = fallback(void 0, queryToBoolean(routeParams.displayArticle), false) ? "1" : "0";
displayComments = fallback(void 0, queryToBoolean(routeParams.displayComments), false) ? "1" : "0";
showRetweeted = fallback(void 0, queryToBoolean(routeParams.showRetweeted), false) ? "1" : "0";
showBloggerIcons = fallback(void 0, queryToBoolean(routeParams.showBloggerIcons), false) ? "1" : "0";
}
const containerData = await utils_default.tryWithCookies((cookies) => cache_default.tryGet(`weibo:user:index:${uid}`, async () => {
return (await got_default({
method: "get",
url: `https://m.weibo.cn/api/container/getIndex?type=uid&value=${uid}`,
headers: {
Referer: `https://m.weibo.cn/u/${uid}`,
Cookie: cookies,
...utils_default.apiHeaders
}
})).data;
}, config.cache.routeExpire, false));
const name = containerData.data.userInfo.screen_name;
const description = containerData.data.userInfo.description;
const profileImageUrl = containerData.data.userInfo.profile_image_url;
const containerId = containerData.data.tabsInfo.tabs.find((item) => item.tab_type === "weibo").containerid;
const cards = await utils_default.tryWithCookies((cookies) => cache_default.tryGet(`weibo:user:cards:${uid}:${containerId}`, async () => {
return (await got_default({
method: "get",
url: `https://m.weibo.cn/api/container/getIndex?type=uid&value=${uid}&containerid=${containerId}`,
headers: {
Referer: `https://m.weibo.cn/u/${uid}`,
Cookie: cookies,
...utils_default.apiHeaders
}
})).data.data.cards;
}, config.cache.routeExpire, false));
let resultItems = await Promise.all(cards.filter((item) => {
if (item.mblog === void 0) return false;
if (showRetweeted === "0" && item.mblog.retweeted_status) return false;
return true;
}).map(async (item) => {
let { bid } = item.mblog;
const { retweeted_status, created_at } = item.mblog;
if (bid === "") {
bid = new URL(item.scheme).searchParams.get("mblogid");
item.mblog.bid = bid;
}
const key = `weibo:user:${bid}`;
const data = await cache_default.tryGet(key, () => utils_default.getShowData(uid, bid));
if (data && data.text) {
item.mblog.text = data.text;
item.mblog.created_at = parseDate(data.created_at);
item.mblog.pics = data.pics;
if (retweeted_status && data.retweeted_status) retweeted_status.created_at = data.retweeted_status.created_at;
} else item.mblog.created_at = timezone(created_at, 8);
const retweet = retweeted_status;
if (retweet && retweet.isLongText) {
const retweetData = await cache_default.tryGet(`weibo:retweeted:${retweet.user.id}:${retweet.bid}`, () => utils_default.getShowData(retweet.user.id, retweet.bid));
if (retweetData !== void 0 && retweetData.text) retweeted_status.text = retweetData.text;
}
const formatExtended = utils_default.formatExtended(ctx, item.mblog, uid);
let description$1 = formatExtended.description;
if (displayVideo === "1") description$1 = retweeted_status ? utils_default.formatVideo(description$1, retweeted_status) : utils_default.formatVideo(description$1, item.mblog);
if (displayComments === "1") description$1 = await utils_default.formatComments(ctx, description$1, item.mblog, showBloggerIcons);
if (displayArticle === "1") description$1 = await (retweeted_status ? utils_default.formatArticle(ctx, description$1, retweeted_status) : utils_default.formatArticle(ctx, description$1, item.mblog));
return {
...formatExtended,
description: description$1,
isPinned: item.profile_type_id?.startsWith("proweibotop")
};
}));
const pinnedItems = resultItems.filter((item) => item.isPinned);
const ordinaryItems = resultItems.filter((item) => !item.isPinned);
if (pinnedItems.length > 0 && ordinaryItems.length > 0) {
const earliestOrdinaryPostTime = Math.min(...ordinaryItems.map((i) => i.pubDate).filter(Boolean));
resultItems = ordinaryItems;
for (const item of pinnedItems) if (item.pubDate > earliestOrdinaryPostTime) resultItems.unshift(item);
}
return utils_default.sinaimgTvax({
title: `${name}的微博`,
link: `https://weibo.com/${uid}/`,
description,
image: profileImageUrl,
item: resultItems,
allowEmpty: true
});
}
//#endregion
export { route };