mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-06 11:00:54 +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.length === 2 &&
|
||||||
language !== tweet.legacy.lang
|
language !== tweet.legacy.lang
|
||||||
) {
|
) {
|
||||||
|
console.log(`Attempting to translate Tweet to ${language}...`);
|
||||||
const translateAPI = await translateTweet(
|
const translateAPI = await translateTweet(
|
||||||
tweet,
|
tweet,
|
||||||
conversation.guestToken || '',
|
conversation.guestToken || '',
|
||||||
|
@ -252,12 +253,11 @@ export const statusAPI = async (
|
||||||
if (!tweet) {
|
if (!tweet) {
|
||||||
return { code: 404, message: 'NOT_FOUND' };
|
return { code: 404, message: 'NOT_FOUND' };
|
||||||
}
|
}
|
||||||
const conversation: any[] = [];
|
|
||||||
/* Creating the response objects */
|
/* Creating the response objects */
|
||||||
const response: TweetAPIResponse = { code: 200, message: 'OK' } as TweetAPIResponse;
|
const response: TweetAPIResponse = { code: 200, message: 'OK' } as TweetAPIResponse;
|
||||||
const apiTweet: APITweet = (await populateTweetProperties(
|
const apiTweet: APITweet = (await populateTweetProperties(
|
||||||
tweet,
|
tweet,
|
||||||
conversation,
|
res,
|
||||||
language
|
language
|
||||||
)) as APITweet;
|
)) as APITweet;
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ export const statusAPI = async (
|
||||||
if (quoteTweet) {
|
if (quoteTweet) {
|
||||||
apiTweet.quote = (await populateTweetProperties(
|
apiTweet.quote = (await populateTweetProperties(
|
||||||
quoteTweet,
|
quoteTweet,
|
||||||
conversation,
|
res,
|
||||||
language
|
language
|
||||||
)) as APITweet;
|
)) as APITweet;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,23 +19,33 @@ export const translateTweet = async (
|
||||||
].join('; '),
|
].join('; '),
|
||||||
'x-csrf-token': csrfToken,
|
'x-csrf-token': csrfToken,
|
||||||
'x-twitter-active-user': 'yes',
|
'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;
|
let translationResults: TranslationPartial;
|
||||||
|
|
||||||
headers['x-twitter-client-language'] = language;
|
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 {
|
try {
|
||||||
apiRequest = await fetch(
|
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`;
|
||||||
`${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',
|
method: 'GET',
|
||||||
headers: headers
|
headers: headers
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
translationResults = (await apiRequest.json()) as TranslationPartial;
|
translationResults = (await translationApiResponse.json()) as TranslationPartial;
|
||||||
|
|
||||||
|
console.log(`translationResults`, translationResults);
|
||||||
|
|
||||||
if (translationResults.translationState !== 'Success') {
|
if (translationResults.translationState !== 'Success') {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue