Merge pull request #625 from FixTweet/discord-native-multi-image

Implement Discord native multi-image
This commit is contained in:
dangered wolf 2024-01-22 02:54:14 -05:00 committed by GitHub
commit 059eb8f2bd
Signed by: DevComp
GPG key ID: B5690EEEBB952194
9 changed files with 45 additions and 11 deletions

View file

@ -4,6 +4,7 @@ DIRECT_MEDIA_DOMAINS = "d.fxtwitter.com,dl.fxtwitter.com,d.twittpr.com,dl.twittp
TEXT_ONLY_DOMAINS = "t.fxtwitter.com,t.twittpr.com,t.fixupx.com" TEXT_ONLY_DOMAINS = "t.fxtwitter.com,t.twittpr.com,t.fixupx.com"
INSTANT_VIEW_DOMAINS = "i.fxtwitter.com,i.twittpr.com,i.fixupx.com" INSTANT_VIEW_DOMAINS = "i.fxtwitter.com,i.twittpr.com,i.fixupx.com"
GALLERY_DOMAINS = "g.fxtwitter.com,g.twittpr.com,g.fixupx.com" GALLERY_DOMAINS = "g.fxtwitter.com,g.twittpr.com,g.fixupx.com"
FORCE_MOSAIC_DOMAINS = "m.fxtwitter.com,m.twittpr.com,m.fixupx.com"
MOSAIC_DOMAIN_LIST = "mosaic.fxtwitter.com" MOSAIC_DOMAIN_LIST = "mosaic.fxtwitter.com"
API_HOST_LIST = "api.fxtwitter.com,api-canary.fxtwitter.com" API_HOST_LIST = "api.fxtwitter.com,api-canary.fxtwitter.com"
HOST_URL = "https://fxtwitter.com" HOST_URL = "https://fxtwitter.com"

View file

@ -38,6 +38,7 @@ let envVariables = [
'TEXT_ONLY_DOMAINS', 'TEXT_ONLY_DOMAINS',
'INSTANT_VIEW_DOMAINS', 'INSTANT_VIEW_DOMAINS',
'GALLERY_DOMAINS', 'GALLERY_DOMAINS',
'FORCE_MOSAIC_DOMAINS',
'HOST_URL', 'HOST_URL',
'REDIRECT_URL', 'REDIRECT_URL',
'EMBED_URL', 'EMBED_URL',

View file

@ -8,6 +8,7 @@
"TEXT_ONLY_DOMAINS": "t.fxtwitter.com,t.twittpr.com,t.fixupx.com", "TEXT_ONLY_DOMAINS": "t.fxtwitter.com,t.twittpr.com,t.fixupx.com",
"INSTANT_VIEW_DOMAINS": "i.fxtwitter.com,i.twittpr.com,i.fixupx.com", "INSTANT_VIEW_DOMAINS": "i.fxtwitter.com,i.twittpr.com,i.fixupx.com",
"GALLERY_DOMAINS": "g.fxtwitter.com,g.twittpr.com,g.fixupx.com", "GALLERY_DOMAINS": "g.fxtwitter.com,g.twittpr.com,g.fixupx.com",
"FORCE_MOSAIC_DOMAINS": "m.fxtwitter.com,m.twittpr.com,m.fixupx.com",
"STANDARD_DOMAIN_LIST": "fxtwitter.com,fixupx.com,twittpr.com", "STANDARD_DOMAIN_LIST": "fxtwitter.com,fixupx.com,twittpr.com",
"DIRECT_MEDIA_DOMAINS": "d.fxtwitter.com,dl.fxtwitter.com,d.fixupx.com,dl.fixupx.com", "DIRECT_MEDIA_DOMAINS": "d.fxtwitter.com,dl.fxtwitter.com,d.fixupx.com,dl.fixupx.com",
"MOSAIC_DOMAIN_LIST": "mosaic.fxtwitter.com", "MOSAIC_DOMAIN_LIST": "mosaic.fxtwitter.com",

View file

@ -6,6 +6,7 @@ export const Constants = {
TEXT_ONLY_DOMAINS: TEXT_ONLY_DOMAINS.split(','), TEXT_ONLY_DOMAINS: TEXT_ONLY_DOMAINS.split(','),
INSTANT_VIEW_DOMAINS: INSTANT_VIEW_DOMAINS.split(','), INSTANT_VIEW_DOMAINS: INSTANT_VIEW_DOMAINS.split(','),
GALLERY_DOMAINS: GALLERY_DOMAINS.split(','), GALLERY_DOMAINS: GALLERY_DOMAINS.split(','),
FORCE_MOSAIC_DOMAINS: FORCE_MOSAIC_DOMAINS.split(','),
MOSAIC_DOMAIN_LIST: MOSAIC_DOMAIN_LIST.split(','), MOSAIC_DOMAIN_LIST: MOSAIC_DOMAIN_LIST.split(','),
API_HOST_LIST: API_HOST_LIST.split(','), API_HOST_LIST: API_HOST_LIST.split(','),
HOST_URL: HOST_URL, HOST_URL: HOST_URL,

View file

@ -8,6 +8,7 @@ import { renderPhoto } from '../render/photo';
import { renderVideo } from '../render/video'; import { renderVideo } from '../render/video';
import { renderInstantView } from '../render/instantview'; import { renderInstantView } from '../render/instantview';
import { constructTwitterThread } from '../providers/twitter/conversation'; import { constructTwitterThread } from '../providers/twitter/conversation';
import { Experiment, experimentCheck } from '../experiments';
export const returnError = (c: Context, error: string): Response => { export const returnError = (c: Context, error: string): Response => {
return c.html( return c.html(
@ -98,6 +99,7 @@ export const handleStatus = async (
} }
const isTelegram = (userAgent || '').indexOf('Telegram') > -1; const isTelegram = (userAgent || '').indexOf('Telegram') > -1;
const isDiscord = (userAgent || '').indexOf('Discord') > -1;
/* Should sensitive statuses be allowed Instant View? */ /* Should sensitive statuses be allowed Instant View? */
let useIV = let useIV =
isTelegram /*&& !status.possibly_sensitive*/ && isTelegram /*&& !status.possibly_sensitive*/ &&
@ -289,16 +291,33 @@ export const handleStatus = async (
siteName = instructions.siteName; siteName = instructions.siteName;
} }
} else if (media?.mosaic) { } else if (media?.mosaic) {
const instructions = renderPhoto( if (experimentCheck(Experiment.DISCORD_NATIVE_MULTI_IMAGE, isDiscord) && !flags.forceMosaic) {
{ const photos = status.media?.photos || [];
status: status,
authorText: authorText, photos.forEach(photo => {
engagementText: engagementText, const instructions = renderPhoto(
userAgent: userAgent {
}, status: status,
media.mosaic authorText: authorText,
); engagementText: engagementText,
headers.push(...instructions.addHeaders); userAgent: userAgent
},
photo
);
headers.push(...instructions.addHeaders);
});
} else {
const instructions = renderPhoto(
{
status: status,
authorText: authorText,
engagementText: engagementText,
userAgent: userAgent
},
media.mosaic
);
headers.push(...instructions.addHeaders);
}
} else if (media?.photos) { } else if (media?.photos) {
const instructions = renderPhoto( const instructions = renderPhoto(
{ {

View file

@ -1,7 +1,8 @@
export enum Experiment { export enum Experiment {
ELONGATOR_BY_DEFAULT = 'ELONGATOR_BY_DEFAULT', ELONGATOR_BY_DEFAULT = 'ELONGATOR_BY_DEFAULT',
ELONGATOR_PROFILE_API = 'ELONGATOR_PROFILE_API', ELONGATOR_PROFILE_API = 'ELONGATOR_PROFILE_API',
TWEET_DETAIL_API = 'TWEET_DETAIL_API' TWEET_DETAIL_API = 'TWEET_DETAIL_API',
DISCORD_NATIVE_MULTI_IMAGE = 'DISCORD_NATIVE_MULTI_IMAGE'
} }
type ExperimentConfig = { type ExperimentConfig = {
@ -25,6 +26,11 @@ const Experiments: { [key in Experiment]: ExperimentConfig } = {
name: 'Tweet detail API', name: 'Tweet detail API',
description: 'Use Tweet Detail API (where available with elongator)', description: 'Use Tweet Detail API (where available with elongator)',
percentage: 0.75 percentage: 0.75
},
[Experiment.DISCORD_NATIVE_MULTI_IMAGE]: {
name: 'Discord native multi-image',
description: 'Use Discord native multi-image',
percentage: 0.5
} }
}; };

View file

@ -58,6 +58,9 @@ export const statusRequest = async (c: Context) => {
} else if (Constants.GALLERY_DOMAINS.includes(url.hostname)) { } else if (Constants.GALLERY_DOMAINS.includes(url.hostname)) {
console.log('Gallery embed request'); console.log('Gallery embed request');
flags.gallery = true; flags.gallery = true;
} else if (Constants.FORCE_MOSAIC_DOMAINS.includes(url.hostname)) {
console.log('Force mosaic request');
flags.forceMosaic = true;
} else if (prefix === 'dl' || prefix === 'dir') { } else if (prefix === 'dl' || prefix === 'dir') {
console.log('Direct media request by path prefix'); console.log('Direct media request by path prefix');
flags.direct = true; flags.direct = true;

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

@ -4,6 +4,7 @@ declare const DIRECT_MEDIA_DOMAINS: string;
declare const TEXT_ONLY_DOMAINS: string; declare const TEXT_ONLY_DOMAINS: string;
declare const INSTANT_VIEW_DOMAINS: string; declare const INSTANT_VIEW_DOMAINS: string;
declare const GALLERY_DOMAINS: string; declare const GALLERY_DOMAINS: string;
declare const FORCE_MOSAIC_DOMAINS: string;
declare const HOST_URL: string; declare const HOST_URL: string;
declare const EMBED_URL: string; declare const EMBED_URL: string;
declare const REDIRECT_URL: string; declare const REDIRECT_URL: string;

View file

@ -10,6 +10,7 @@ type InputFlags = {
forceInstantView?: boolean; forceInstantView?: boolean;
archive?: boolean; archive?: boolean;
gallery?: boolean; gallery?: boolean;
forceMosaic?: boolean;
}; };
interface StatusResponse { interface StatusResponse {