diff --git a/lib/routes/twitter/user.ts b/lib/routes/twitter/user.ts index a8bb96e54..2dcc6209c 100644 --- a/lib/routes/twitter/user.ts +++ b/lib/routes/twitter/user.ts @@ -82,9 +82,13 @@ async function handler(ctx) { description: userInfo?.description, item: data && - utils.ProcessFeed(ctx, { - data, - }), + utils.ProcessFeed( + ctx, + { + data, + }, + { userScreenName: userInfo?.screen_name, userName: userInfo?.name } + ), allowEmpty: true, }; } diff --git a/lib/routes/twitter/utils.ts b/lib/routes/twitter/utils.ts index a6d2bc2f9..f611a7d1a 100644 --- a/lib/routes/twitter/utils.ts +++ b/lib/routes/twitter/utils.ts @@ -68,6 +68,8 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { sizeOfAuthorAvatar: fallback(params.sizeOfAuthorAvatar, queryToInteger(routeParams.get('sizeOfAuthorAvatar')), 48), sizeOfQuotedAuthorAvatar: fallback(params.sizeOfQuotedAuthorAvatar, queryToInteger(routeParams.get('sizeOfQuotedAuthorAvatar')), 24), mediaNumber: fallback(params.mediaNumber, queryToInteger(routeParams.get('mediaNumber')), false), + userScreenName: params.userScreenName, + userName: params.userName, }; params = mergedParams; @@ -91,6 +93,8 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { heightOfPics, sizeOfAuthorAvatar, sizeOfQuotedAuthorAvatar, + userScreenName, + userName, } = params; const formatVideo = (media, extraAttrs = '') => { @@ -280,7 +284,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { // Make title let title = ''; if (showAuthorInTitle) { - title += originalItem.user.name + ': '; + title += userName + ': '; } const isRetweet = originalItem !== item; const isQuote = item.is_quote_status; @@ -304,7 +308,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { } if (showAuthorAsTitleOnly) { - title = originalItem.user.name; + title = userName; } // Make description @@ -316,12 +320,12 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { if (showAuthorInDesc) { if (readable) { description += ''; - description += ``; + description += ``; } if (authorNameBold) { description += ``; } - description += originalItem.user.name; + description += userName; if (authorNameBold) { description += ``; } @@ -334,12 +338,12 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { if (!showAuthorInDesc) { description += ' '; if (readable) { - description += ``; + description += ``; } if (authorNameBold) { description += ``; } - description += item.user.name; + description += item.user?.name || userName; if (authorNameBold) { description += ``; } @@ -354,7 +358,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { } if (showAuthorInDesc) { if (readable) { - description += ``; + description += ``; } if (showAuthorAvatarInDesc) { @@ -363,7 +367,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { if (authorNameBold) { description += ``; } - description += item.user.name; + description += item.user?.name || userName; if (authorNameBold) { description += ``; } @@ -393,16 +397,16 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { } const link = - originalItem.user.screen_name && (originalItem.id_str || originalItem.conversation_id_str) - ? `https://x.com/${originalItem.user.screen_name}/status/${originalItem.id_str || originalItem.conversation_id_str}` - : `https://x.com/${item.user.screen_name}/status/${item.id_str || item.conversation_id_str}`; + userScreenName && (originalItem.id_str || originalItem.conversation_id_str) + ? `https://x.com/${userScreenName}/status/${originalItem.id_str || originalItem.conversation_id_str}` + : `https://x.com/${item.user?.screen_name || userScreenName}/status/${item.id_str || item.conversation_id_str}`; return { title, author: [ { - name: originalItem.user.name, - url: `https://x.com/${originalItem.user.screen_name}`, - avatar: originalItem.user.profile_image_url_https, + name: userName, + url: `https://x.com/${userScreenName}`, + avatar: originalItem.user?.profile_image_url_https, }, ], description, @@ -414,7 +418,7 @@ const ProcessFeed = (ctx, { data = [] }, params = {}) => { (isRetweet && { links: [ { - url: `https://x.com/${item.user?.screen_name}/status/${item.conversation_id_str}`, + url: `https://x.com/${item.user?.screen_name || userScreenName}/status/${item.conversation_id_str}`, type: 'repost', }, ],