rsshub
Version:
Make RSS Great Again!
111 lines (108 loc) • 4.53 kB
JavaScript
import { t as config } from "./config-CCmw1BNE.mjs";
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { t as got_default } from "./got-BTowW50G.mjs";
import { t as ConfigNotFoundError } from "./config-not-found-fQ5mxvDU.mjs";
import { n as queryToBoolean, t as fallback } from "./readable-social-DP5kGwF5.mjs";
import { t as weiboUtils } from "./utils-Ds-mYZZM.mjs";
import querystring from "node:querystring";
//#region lib/routes/weibo/friends.ts
const route = {
path: "/friends/:routeParams?",
categories: ["social-media"],
example: "/weibo/friends",
parameters: { routeParams: "额外参数;请参阅上面的说明和表格" },
features: {
requireConfig: [{
name: "WEIBO_COOKIES",
optional: true,
description: ""
}],
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["weibo.com/"],
target: "/friends"
}],
name: "最新关注时间线",
maintainers: ["CaoMeiYouRen"],
handler,
url: "weibo.com/",
description: `::: warning
此方案必须使用用户\`Cookie\`进行抓取
因微博 cookies 的过期与更新方案未经验证,部署一次 Cookie 的有效时长未知
微博用户 Cookie 的配置可参照部署文档
:::`
};
async function handler(ctx) {
if (!config.weibo.cookies) throw new ConfigNotFoundError("Weibo Friends Timeline is not available due to the absense of [Weibo Cookies]. Check <a href=\"https://docs.rsshub.app/deploy/config#route-specific-configurations\">relevant config tutorial</a>");
let displayVideo = "1";
let displayArticle = "0";
let displayComments = "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";
}
const uid = await cache_default.tryGet("weibo:friends:login-user", async () => {
return (await got_default({
method: "get",
url: "https://m.weibo.cn/api/config",
headers: {
Referer: "https://m.weibo.cn/",
Cookie: config.weibo.cookies,
...weiboUtils.apiHeaders
}
})).data.data.uid;
}, config.cache.routeExpire, false);
const title = `${(await 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: config.weibo.cookies,
...weiboUtils.apiHeaders
}
})).data;
}, config.cache.routeExpire, false)).data.userInfo.screen_name} 的 最新关注时间线`;
const responseData = await cache_default.tryGet(`weibo:friends:index:${uid}`, async () => {
return (await got_default({
method: "get",
url: "https://m.weibo.cn/feed/friends",
headers: {
Referer: "https://m.weibo.cn/",
Cookie: config.weibo.cookies,
...weiboUtils.apiHeaders
}
})).data.data;
}, config.cache.routeExpire, false);
const resultItems = await Promise.all(responseData.statuses.map(async (item) => {
const retweet = item.retweeted_status;
if (retweet && retweet.isLongText) {
const retweetData = await cache_default.tryGet(`weibo:retweeted:${retweet.user.id}:${retweet.bid}`, () => weiboUtils.getShowData(retweet.user.id, retweet.bid));
if (retweetData !== void 0 && retweetData.text) item.retweeted_status.text = retweetData.text;
}
const formatExtended = weiboUtils.formatExtended(ctx, item);
let description = formatExtended.description;
if (displayVideo === "1") description = item.retweeted_status ? weiboUtils.formatVideo(description, item.retweeted_status) : weiboUtils.formatVideo(description, item);
if (displayComments === "1") description = await weiboUtils.formatComments(ctx, description, item, "0");
if (displayArticle === "1") description = await (item.retweeted_status ? weiboUtils.formatArticle(ctx, description, item.retweeted_status) : weiboUtils.formatArticle(ctx, description, item));
return {
...formatExtended,
description
};
}));
return weiboUtils.sinaimgTvax({
title,
link: "https://weibo.com",
item: resultItems
});
}
//#endregion
export { route };