const utils = require('./utils'); const config = require('@/config').value; module.exports = async (ctx) => { if (!config.twitter || !config.twitter.consumer_key || !config.twitter.consumer_secret) { throw 'Twitter RSS is disabled due to the lack of relevant config'; } const id = ctx.params.id; const type = ctx.params.type; let exclude_replies = false; let include_rts = true; if (type === 'exclude_rts_replies' || type === 'exclude_replies_rts') { exclude_replies = true; include_rts = false; } if (type === 'exclude_replies') { exclude_replies = true; include_rts = true; } if (type === 'exclude_rts') { exclude_replies = false; include_rts = false; } const result = await utils.getTwit().get('statuses/user_timeline', { screen_name: id, tweet_mode: 'extended', exclude_replies, include_rts, }); const data = result.data; const userInfo = data[0].user; const profileImageUrl = userInfo.profile_image_url || userInfo.profile_image_url_https; ctx.state.data = { title: `${userInfo.name} 的 Twitter`, link: `https://twitter.com/${id}/`, image: profileImageUrl, description: userInfo.description, item: utils.ProcessFeed({ data, }), }; };