fix(route): fix /twitter/likes (#15384)

* fix(route): fix /twitter/likes

* fix: delete not used variables

* update: router /twitter/likes config

* feat: throw a error for Twitter Premium accounts.

* feat: throw a error for Twitter Premium accounts
This commit is contained in:
Alan Xian
2024-05-04 23:09:33 +08:00
committed by GitHub
parent 41a8eec47f
commit 75d8152540
4 changed files with 35 additions and 13 deletions
+14 -1
View File
@@ -97,7 +97,20 @@ const getUserMedia = (id: string, params?: Record<string, any>) =>
);
});
const getUserLikes = (id: string, params?: Record<string, any>) => cacheTryGet(id, params, async (id, params = {}) => gatherLegacyFromData(await paginationTweets('Likes', id, params)));
const getUserLikes = (id: string, params?: Record<string, any>) =>
cacheTryGet(id, params, async (id, params = {}) =>
gatherLegacyFromData(
await paginationTweets(
'Likes',
id,
{
...params,
includeHasBirdwatchNotes: false,
includePromotedContent: false,
withBirdwatchNotes: false,
withVoice: false,
withV2Timeline: true,
})));
const getUserTweet = (id: string, params?: Record<string, any>) =>
cacheTryGet(id, params, async (id, params = {}) =>
@@ -88,6 +88,7 @@ const gqlFeatures = {
ListLatestTweetsTimeline: gqlFeatureFeed,
HomeTimeline: gqlFeatureFeed,
TweetDetail: TweetDetailFeatures,
Likes: gqlFeatureFeed
};
const timelineParams = {
+5 -1
View File
@@ -63,7 +63,11 @@ export const paginationTweets = async (endpoint: string, userId: number | undefi
}
instructions = instructions.instructions;
} else {
instructions = data.user.result.timeline_v2.timeline.instructions;
if (data?.user?.result?.timeline_v2?.timeline?.instructions) {
instructions = data.user.result.timeline_v2.timeline.instructions;
} else {
throw new Error('Because Twitter Premium has features that hide your likes, this RSS link is not available for Twitter Premium accounts.');
}
}
const entries1 = instructions.find((i) => i.type === 'TimelineAddToModule')?.moduleItems; // Media
+15 -11
View File
@@ -1,7 +1,6 @@
import { Route } from '@/types';
import utils from './utils';
import { config } from '@/config';
import ConfigNotFoundError from '@/errors/types/config-not-found';
import api from './api';
export const route: Route = {
path: '/likes/:id/:routeParams?',
@@ -9,7 +8,12 @@ export const route: Route = {
example: '/twitter/likes/DIYgod',
parameters: { id: 'username', routeParams: 'extra parameters, see the table above' },
features: {
requireConfig: false,
requireConfig: [
{
name: 'TWITTER_COOKIE',
description: 'Please see above for details.',
},
],
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
@@ -22,15 +26,15 @@ export const route: Route = {
};
async function handler(ctx) {
if (!config.twitter || !config.twitter.consumer_key || !config.twitter.consumer_secret) {
throw new ConfigNotFoundError('Twitter RSS is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#route-specific-configurations">relevant config</a>');
}
const id = ctx.req.param('id');
const client = await utils.getAppClient();
const data = await client.v1.get('favorites/list.json', {
screen_name: id,
tweet_mode: 'extended',
});
const { count, include_rts } = utils.parseRouteParams(ctx.req.param('routeParams'));
const params = count ? { count } : {};
await api.init();
let data = await api.getUserLikes(id, params);
if (!include_rts) {
data = utils.excludeRetweet(data);
}
return {
title: `Twitter Likes - ${id}`,