mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-05 10:30:55 +01:00
Fix translations (1000th commit!)
This commit is contained in:
parent
170cd1d446
commit
d4a6582bd6
2 changed files with 18 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue