Fix translations (1000th commit!)

This commit is contained in:
dangered wolf 2023-08-20 14:51:30 -04:00
parent 170cd1d446
commit d4a6582bd6
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
2 changed files with 18 additions and 8 deletions

View file

@ -152,6 +152,7 @@ const populateTweetProperties = async (
language.length === 2 &&
language !== tweet.legacy.lang
) {
console.log(`Attempting to translate Tweet to ${language}...`);
const translateAPI = await translateTweet(
tweet,
conversation.guestToken || '',
@ -252,12 +253,11 @@ export const statusAPI = async (
if (!tweet) {
return { code: 404, message: 'NOT_FOUND' };
}
const conversation: any[] = [];
/* Creating the response objects */
const response: TweetAPIResponse = { code: 200, message: 'OK' } as TweetAPIResponse;
const apiTweet: APITweet = (await populateTweetProperties(
tweet,
conversation,
res,
language
)) as APITweet;
@ -266,7 +266,7 @@ export const statusAPI = async (
if (quoteTweet) {
apiTweet.quote = (await populateTweetProperties(
quoteTweet,
conversation,
res,
language
)) as APITweet;
}

View file

@ -19,23 +19,33 @@ export const translateTweet = async (
].join('; '),
'x-csrf-token': csrfToken,
'x-twitter-active-user': 'yes',
'x-guest-token': guestToken
'x-guest-token': guestToken,
'Referer': `${Constants.TWITTER_ROOT}/i/status/${tweet.rest_id}`,
};
let apiRequest;
let translationApiResponse;
let translationResults: TranslationPartial;
headers['x-twitter-client-language'] = language;
/* As of August 2023, you can no longer fetch translations with guest token */
if (typeof TwitterProxy === 'undefined') {
return null
}
try {
apiRequest = await fetch(
`${Constants.TWITTER_ROOT}/i/api/1.1/strato/column/None/tweetId=${tweet.rest_id},destinationLanguage=None,translationSource=Some(Google),feature=None,timeout=None,onlyCached=None/translation/service/translateTweet`,
const url = `${Constants.TWITTER_ROOT}/i/api/1.1/strato/column/None/tweetId=${tweet.rest_id},destinationLanguage=None,translationSource=Some(Google),feature=None,timeout=None,onlyCached=None/translation/service/translateTweet`;
console.log(url, headers);
translationApiResponse = await TwitterProxy.fetch(
url,
{
method: 'GET',
headers: headers
}
);
translationResults = (await apiRequest.json()) as TranslationPartial;
translationResults = (await translationApiResponse.json()) as TranslationPartial;
console.log(`translationResults`, translationResults);
if (translationResults.translationState !== 'Success') {
return null;