Change GIF_TRANSCODE_DOMAIN to GIF_TRANSCODE_DOMAIN_LIST

This commit is contained in:
dangered wolf 2024-08-05 17:15:03 -07:00
parent 174cc65782
commit c1ef1f3ba7
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
5 changed files with 22 additions and 6 deletions

View file

@ -15,4 +15,4 @@ SENTRY_DSN = ""
SENTRY_AUTH_TOKEN = ""
SENTRY_ORG = ""
SENTRY_PROJECT = ""
GIF_TRANSCODE_DOMAIN = "gif.fxtwitter.com"
GIF_TRANSCODE_DOMAIN_LIST = "gif.fxtwitter.com"

View file

@ -46,7 +46,7 @@ let envVariables = [
'MOSAIC_DOMAIN_LIST',
'API_HOST_LIST',
'SENTRY_DSN',
'GIF_TRANSCODE_DOMAIN'
'GIF_TRANSCODE_DOMAIN_LIST'
];
// Create defines for all environment variables

View file

@ -18,7 +18,7 @@
"REDIRECT_URL": "https://github.com/FixTweet/FxTwitter",
"EMBED_URL": "https://github.com/FixTweet/FxTwitter",
"RELEASE_NAME": "fixtweet-test",
"GIF_TRANSCODE_DOMAIN": "gif.fxtwitter.com",
"GIF_TRANSCODE_DOMAIN_LIST": "gif.fxtwitter.com",
"SENTRY_DSN": null
},
"testRegex": "/test/.*\\.test\\.ts$",

View file

@ -3,6 +3,22 @@ import { Constants } from '../constants';
import { Experiment, experimentCheck } from '../experiments';
import { handleQuote } from '../helpers/quote';
const getGIFTranscodeDomain = (twitterId: string): string | null => {
const gifTranscoderList = Constants.GIF_TRANSCODE_DOMAIN_LIST;
if (gifTranscoderList.length === 0) {
return null;
}
let hash = 0;
for (let i = 0; i < twitterId.length; i++) {
const char = twitterId.charCodeAt(i);
hash = (hash << 5) - hash + char;
}
return gifTranscoderList[Math.abs(hash) % gifTranscoderList.length];
};
export const renderVideo = (
properties: RenderProperties,
video: APIVideo
@ -53,13 +69,13 @@ export const renderVideo = (
let url = video.url;
if (
experimentCheck(Experiment.TRANSCODE_GIFS, !!Constants.GIF_TRANSCODE_DOMAIN) &&
experimentCheck(Experiment.TRANSCODE_GIFS, !!Constants.GIF_TRANSCODE_DOMAIN_LIST) &&
!userAgent?.includes('Telegram') &&
video.type === 'gif'
) {
url = video.url.replace(
Constants.TWITTER_VIDEO_BASE,
`https://${Constants.GIF_TRANSCODE_DOMAIN}`
`https://${getGIFTranscodeDomain(status.id)}`
);
console.log('We passed checks for transcoding GIFs, feeding embed url', url);
}

2
src/types/env.d.ts vendored
View file

@ -11,7 +11,7 @@ declare const EMBED_URL: string;
declare const REDIRECT_URL: string;
declare const MOSAIC_DOMAIN_LIST: string;
declare const API_HOST_LIST: string;
declare const GIF_TRANSCODE_DOMAIN: string;
declare const GIF_TRANSCODE_DOMAIN_LIST: string;
declare const SENTRY_DSN: string;
declare const RELEASE_NAME: string;