Skip to content

Commit

Permalink
Change GIF_TRANSCODE_DOMAIN to GIF_TRANSCODE_DOMAIN_LIST
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeredwolf committed Aug 6, 2024
1 parent 174cc65 commit c1ef1f3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jestconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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$",
Expand Down
20 changes: 18 additions & 2 deletions src/render/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit c1ef1f3

Please sign in to comment.