feat(route): Weibo Routing Add User Latest Follow Timeline | 微博路由 添加 用户最新关注时间线 (#14385)
* feat(route): 微博路由 添加 用户最新关注时间线 * fix(route): 优化 微博最新关注时间线 的标题显示 ---------
This commit is contained in:
parent
52bcabde30
commit
4224b97ad7
|
|
@ -0,0 +1,122 @@
|
|||
const querystring = require('querystring');
|
||||
const got = require('@/utils/got');
|
||||
const config = require('@/config').value;
|
||||
const weiboUtils = require('./utils');
|
||||
const { fallback, queryToBoolean } = require('@/utils/readable-social');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
if (!config.weibo.cookies) {
|
||||
throw 'Weibo Friends Timeline is not available due to the absense of [Weibo Cookies]. Check <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config tutorial</a>';
|
||||
}
|
||||
|
||||
let displayVideo = '1';
|
||||
let displayArticle = '0';
|
||||
let displayComments = '0';
|
||||
if (ctx.params.routeParams) {
|
||||
if (ctx.params.routeParams === '1' || ctx.params.routeParams === '0') {
|
||||
displayVideo = ctx.params.routeParams;
|
||||
} else {
|
||||
const routeParams = querystring.parse(ctx.params.routeParams);
|
||||
displayVideo = fallback(undefined, queryToBoolean(routeParams.displayVideo), true) ? '1' : '0';
|
||||
displayArticle = fallback(undefined, queryToBoolean(routeParams.displayArticle), false) ? '1' : '0';
|
||||
displayComments = fallback(undefined, queryToBoolean(routeParams.displayComments), false) ? '1' : '0';
|
||||
}
|
||||
}
|
||||
|
||||
const uid = await ctx.cache.tryGet(
|
||||
`weibo:friends:login-user`,
|
||||
async () => {
|
||||
const _r = await got({
|
||||
method: 'get',
|
||||
url: 'https://m.weibo.cn/api/config',
|
||||
headers: {
|
||||
Referer: `https://m.weibo.cn/`,
|
||||
'MWeibo-Pwa': 1,
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
Cookie: config.weibo.cookies,
|
||||
},
|
||||
});
|
||||
return _r.data.data.uid;
|
||||
},
|
||||
config.cache.routeExpire,
|
||||
false
|
||||
);
|
||||
|
||||
const containerData = await ctx.cache.tryGet(
|
||||
`weibo:user:index:${uid}`,
|
||||
async () => {
|
||||
const _r = await got({
|
||||
method: 'get',
|
||||
url: `https://m.weibo.cn/api/container/getIndex?type=uid&value=${uid}`,
|
||||
headers: {
|
||||
Referer: `https://m.weibo.cn/u/${uid}`,
|
||||
'MWeibo-Pwa': 1,
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
Cookie: config.weibo.cookies,
|
||||
},
|
||||
});
|
||||
return _r.data;
|
||||
},
|
||||
config.cache.routeExpire,
|
||||
false
|
||||
);
|
||||
|
||||
const name = containerData.data.userInfo.screen_name;
|
||||
const title = `${name} 的 最新关注时间线`;
|
||||
|
||||
const responseData = await ctx.cache.tryGet(
|
||||
`weibo:friends:index:${uid}`,
|
||||
async () => {
|
||||
const _r = await got({
|
||||
method: 'get',
|
||||
url: 'https://m.weibo.cn/feed/friends',
|
||||
headers: {
|
||||
Referer: `https://m.weibo.cn/`,
|
||||
'MWeibo-Pwa': 1,
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
Cookie: config.weibo.cookies,
|
||||
},
|
||||
});
|
||||
return _r.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 ctx.cache.tryGet(`weibo:retweeted:${retweet.user.id}:${retweet.bid}`, () => weiboUtils.getShowData(retweet.user.id, retweet.bid));
|
||||
if (retweetData !== undefined && 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);
|
||||
}
|
||||
|
||||
if (displayArticle === '1') {
|
||||
description = await (item.retweeted_status ? weiboUtils.formatArticle(ctx, description, item.retweeted_status) : weiboUtils.formatArticle(ctx, description, item));
|
||||
}
|
||||
|
||||
return {
|
||||
...formatExtended,
|
||||
description,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = weiboUtils.sinaimgTvax({
|
||||
title,
|
||||
link: `https://weibo.com`,
|
||||
item: resultItems,
|
||||
});
|
||||
};
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = {
|
||||
'/friends/:routeParams?': ['CaoMeiYouRen'],
|
||||
'/group/:gid/:gname?/:routeParams?': ['monologconnor', 'Rongronggg9'],
|
||||
'/keyword/:keyword/:routeParams?': ['DIYgod', 'Rongronggg9'],
|
||||
'/oasis/user/:userid': ['kt286'],
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ module.exports = {
|
|||
source: ['/u/:id', '/:id'],
|
||||
target: (params, url, document) => {
|
||||
let uid = document?.documentElement.innerHTML.match(/\$CONFIG\['oid']='(\d+)'/)?.[1];
|
||||
if (!uid && !isNaN(params.id)) {
|
||||
if (!uid && !Number.isNaN(params.id)) {
|
||||
uid = params.id;
|
||||
}
|
||||
return uid ? `/weibo/user/${uid}` : '';
|
||||
|
|
@ -24,6 +24,12 @@ module.exports = {
|
|||
source: '/p/:id/super_index',
|
||||
target: '/weibo/super_index/:id',
|
||||
},
|
||||
{
|
||||
title: '最新关注时间线',
|
||||
docs: 'https://docs.rsshub.app/routes/social-media#wei-bo',
|
||||
source: '/',
|
||||
target: '/weibo/friends',
|
||||
},
|
||||
],
|
||||
s: [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/friends/:routeParams?', require('./friends'));
|
||||
router.get('/group/:gid/:gname?/:routeParams?', require('./group'));
|
||||
router.get('/keyword/:keyword/:routeParams?', require('./keyword'));
|
||||
router.get('/oasis/user/:userid', require('./oasis/user'));
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
<Route author="nczitzk" example="/cia/foia-annual-report" path="/cia/foia-annual-report" notOperational="1" />
|
||||
|
||||
## Constitutional Court of Baden-Württemberg (Germany) {#constitutional-court-of-baden-w%C3%BCrttemberg-germany}
|
||||
## Constitutional Court of Baden-Württemberg (Germany) {#constitutional-court-of-baden-wvrttemberg-germany}
|
||||
|
||||
### Press releases {#constitutional-court-of-baden-w%C3%BCrttemberg-germany-press-releases}
|
||||
### Press releases {#constitutional-court-of-baden-wvrttemberg-germany-press-releases}
|
||||
|
||||
<Route author="quinn-dev" example="/verfghbw/press" path="/verfghbw/press/:keyword?" paramsDesc={['Keyword']} notOperational="1" />
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ See [#app-store-mac-app-store](/routes/program-update#app-store-mac-app-store)
|
|||
|
||||
<Route author="DIYgod" example="/scmp/coronavirus" path="/scmp/coronavirus" />
|
||||
|
||||
### Macao Pagina Electrónica Especial Contra Epidemias: What’s New {#corona-virus-disease-2019-macao-pagina-electr%C3%B3nica-especial-contra-epidemias-what-s-new}
|
||||
### Macao Pagina Electrónica Especial Contra Epidemias: What’s New {#corona-virus-disease-2019-macao-pagina-electronica-especial-contra-epidemias-what-s-new}
|
||||
|
||||
Official Website: [https://www.ssm.gov.mo/apps1/PreventWuhanInfection/en.aspx](https://www.ssm.gov.mo/apps1/PreventWuhanInfection/en.aspx)
|
||||
|
||||
|
|
|
|||
|
|
@ -1525,6 +1525,18 @@ YouTube provides official RSS feeds for channels, for instance [https://www.yout
|
|||
:::
|
||||
</Route>
|
||||
|
||||
### 最新关注时间线 {#wei-bo-zui-xin-guan-zhu-shi-jian-xian}
|
||||
|
||||
<Route author="CaoMeiYouRen" example="/weibo/friends" path="/weibo/friends/:routeParams?" paramsDesc={['额外参数;请参阅上面的说明和表格']} configRequired="1">
|
||||
:::warning
|
||||
此方案必须使用用户`Cookie`进行抓取
|
||||
|
||||
因微博 cookies 的过期与更新方案未经验证,部署一次 Cookie 的有效时长未知
|
||||
|
||||
微博用户 Cookie 的配置可参照部署文档
|
||||
:::
|
||||
</Route>
|
||||
|
||||
### 自定义分组 {#wei-bo-zi-ding-yi-fen-zu}
|
||||
|
||||
<Route author="monologconnor Rongronggg9" example="/weibo/group/4541216424989965" path="/weibo/group/:gid/:gname?/:routeParams?" paramsDesc={['分组id, 在网页版分组地址栏末尾`?gid=`处获取', '分组显示名称; 默认为: `微博分组`', '额外参数;请参阅上面的说明和表格']} configRequired="1">
|
||||
|
|
|
|||
Loading…
Reference in New Issue