forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): 微博自定义分组(使用Cookie) (DIYgod#12514)
* change route 'weibo/user' to fit api could be opened with Share(third-party android weibo clent) * update weibo group route using cookies approach * fix typo * code optimization for /weibo/group; docs for /weibo/group * try fix ESLint error * fix typo and code optimization * fix missing ',' * '/weibo/group' throw error when the cookie is not set
- Loading branch information
1 parent
9bdba06
commit 2bd8e48
Showing
8 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
.vercel | ||
.vscode | ||
.yarn | ||
.yarnrc.yml | ||
.pnp* | ||
|
||
*.swp | ||
*.iml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
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 Group 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>'; | ||
} | ||
|
||
const gid = ctx.params.gid; | ||
const groupName = ctx.params.gname || '微博分组'; | ||
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 responseData = await ctx.cache.tryGet( | ||
`weibo:group:index:${gid}`, | ||
async() => { | ||
const _r = await got({ | ||
method: 'get', | ||
url: `https://m.weibo.cn/feed/group?gid=${gid}`, | ||
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 link = `https://m.weibo.cn/status/${item.bid}`; | ||
const formatExtended = weiboUtils.formatExtended(ctx, item); | ||
let description = formatExtended.description; | ||
const title = formatExtended.title; | ||
const pubDate = item.created_at; | ||
|
||
if (displayVideo === '1') { | ||
if (item.retweeted_status) { | ||
description = weiboUtils.formatVideo(description, item.retweeted_status); | ||
} else { | ||
description = weiboUtils.formatVideo(description, item); | ||
} | ||
} | ||
|
||
if (displayComments === '1') { | ||
description = await weiboUtils.formatComments(ctx, description, item); | ||
} | ||
|
||
if (displayArticle === '1') { | ||
if (item.retweeted_status) { | ||
description = await weiboUtils.formatArticle(ctx, description, item.retweeted_status); | ||
} else { | ||
description = await weiboUtils.formatArticle(ctx, description, item); | ||
} | ||
} | ||
|
||
return { | ||
title, | ||
description, | ||
link, | ||
pubDate, | ||
author: item.user.screen_name | ||
}; | ||
}) | ||
); | ||
|
||
ctx.state.data = weiboUtils.sinaimgTvax({ | ||
title: groupName, | ||
link: `https://weibo.com/mygroups?gid=${gid}`, | ||
description: '微博自定义分组', | ||
item: resultItems, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters