twitter: clean up

This commit is contained in:
dumbmoron 2024-05-03 09:33:10 +00:00
parent 58f8301f21
commit 6c33687279
No known key found for this signature in database

View File

@ -63,8 +63,8 @@ const requestTweet = async(tweetId, token, cookie) => {
if (cookie) { if (cookie) {
headers = { headers = {
...commonHeaders, ...commonHeaders,
'X-Twitter-Auth-Type': 'OAuth2Session',
'content-type': 'application/json', 'content-type': 'application/json',
'X-Twitter-Auth-Type': 'OAuth2Session',
'x-csrf-token': cookie.values().ct0, 'x-csrf-token': cookie.values().ct0,
cookie cookie
} }
@ -81,10 +81,7 @@ const requestTweet = async(tweetId, token, cookie) => {
graphqlTweetURL.searchParams.set('features', tweetFeatures); graphqlTweetURL.searchParams.set('features', tweetFeatures);
let result = await fetch(graphqlTweetURL, { headers }); let result = await fetch(graphqlTweetURL, { headers });
updateCookie(cookie, result.headers);
if (cookie) {
updateCookie(cookie, result.headers);
}
return result return result
} }
@ -124,6 +121,7 @@ export default async function({ id, index, toGif }) {
if (!["Tweet", "TweetWithVisibilityResults"].includes(tweetTypename)) { if (!["Tweet", "TweetWithVisibilityResults"].includes(tweetTypename)) {
return { error: 'ErrorTweetUnavailable' } return { error: 'ErrorTweetUnavailable' }
} }
let tweetResult = tweet.data.tweetResult.result, let tweetResult = tweet.data.tweetResult.result,
baseTweet = tweetResult.legacy, baseTweet = tweetResult.legacy,
repostedTweet = baseTweet?.retweeted_status_result?.result.legacy.extended_entities; repostedTweet = baseTweet?.retweeted_status_result?.result.legacy.extended_entities;
@ -137,7 +135,7 @@ export default async function({ id, index, toGif }) {
media = media?.filter(m => m.video_info?.variants?.length); media = media?.filter(m => m.video_info?.variants?.length);
// check if there's a video at given index (/video/<index>) // check if there's a video at given index (/video/<index>)
if ([0, 1, 2, 3].includes(index) && index < media?.length) { if (index >= 0 && index < media?.length) {
media = [media[index]] media = [media[index]]
} }