feat(twitter): try catch allow empty content

This commit is contained in:
DIYgod
2024-10-06 20:30:31 +08:00
parent 19ea5ccc98
commit bac798ae97
3 changed files with 28 additions and 11 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ const graphQLEndpointsPlain = [
'/graphql/DiTkXJgLqBBxCs7zaYsbtA/HomeLatestTimeline',
'/graphql/bt4TKuFz4T7Ckk-VvQVSow/UserTweetsAndReplies',
'/graphql/dexO_2tohK86JDudXXG3Yw/UserMedia',
'/graphql/tD8zKvQzwY3kdx5yz6YmOw/UserByRestId',
'/graphql/Qw77dDjp9xCpUY-AXwt-yQ/UserByRestId',
'/graphql/UN1i3zUiCWa-6r-Uaho4fw/SearchTimeline',
'/graphql/Pa45JvqZuKcW1plybfgBlQ/ListLatestTweetsTimeline',
'/graphql/QuBlQ6SxNAQCt6-kBiCXCQ/TweetDetail',
+13 -4
View File
@@ -1,6 +1,7 @@
import { Route, ViewType } from '@/types';
import api from './api';
import utils from './utils';
import logger from '@/utils/logger';
export const route: Route = {
path: '/media/:id/:routeParams?',
@@ -47,7 +48,12 @@ async function handler(ctx) {
await api.init();
const userInfo = await api.getUser(id);
const data = await api.getUserMedia(id, params);
let data;
try {
data = await api.getUserMedia(id, params);
} catch (error) {
logger.debug(error);
}
const profileImageUrl = userInfo?.profile_image_url || userInfo?.profile_image_url_https;
return {
@@ -55,8 +61,11 @@ async function handler(ctx) {
link: `https://x.com/${userInfo?.screen_name}/media`,
image: profileImageUrl.replace(/_normal.jpg$/, '.jpg'),
description: userInfo?.description,
item: utils.ProcessFeed(ctx, {
data,
}),
item:
data &&
utils.ProcessFeed(ctx, {
data,
}),
allowEmpty: true,
};
}
+14 -6
View File
@@ -58,9 +58,14 @@ async function handler(ctx) {
await api.init();
const userInfo = await api.getUser(id);
let data = await (exclude_replies ? api.getUserTweets(id, params) : api.getUserTweetsAndReplies(id, params));
if (!include_rts) {
data = utils.excludeRetweet(data);
let data;
try {
data = await (exclude_replies ? api.getUserTweets(id, params) : api.getUserTweetsAndReplies(id, params));
if (!include_rts) {
data = utils.excludeRetweet(data);
}
} catch (error) {
logger.debug(error);
}
const profileImageUrl = userInfo?.profile_image_url || userInfo?.profile_image_url_https;
@@ -70,8 +75,11 @@ async function handler(ctx) {
link: `https://x.com/${userInfo?.screen_name}`,
image: profileImageUrl.replace(/_normal.jpg$/, '.jpg'),
description: userInfo?.description,
item: utils.ProcessFeed(ctx, {
data,
}),
item:
data &&
utils.ProcessFeed(ctx, {
data,
}),
allowEmpty: true,
};
}