Add text-only embeds (Implements #133)

This commit is contained in:
dangered wolf 2023-02-05 15:30:43 -05:00
parent 5dfd74ce99
commit 832c3c243a
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
8 changed files with 16 additions and 3 deletions

View file

@ -1,6 +1,7 @@
BRANDING_NAME = "FixTweet"
BRANDING_NAME_DISCORD = "FixTweet - Embed videos, polls & more!"
DIRECT_MEDIA_DOMAINS = "d.fxtwitter.com,dl.fxtwitter.com,d.pxtwitter.com,d.twittpr.com,dl.pxtwitter.com,dl.twittpr.com"
TEXT_ONLY_DOMAINS = "t.fxtwitter.com,t.twittpr.com"
DEPRECATED_DOMAIN_LIST = "pxtwitter.com,www.pxtwitter.com"
DEPRECATED_DOMAIN_EPOCH = "1559320000000000000"
MOSAIC_DOMAIN_LIST = "mosaic.fxtwitter.com"
@ -10,5 +11,5 @@ REDIRECT_URL = "https://github.com/FixTweet/FixTweet"
EMBED_URL = "https://github.com/FixTweet/FixTweet"
SENTRY_DSN = ""
SENTRY_AUTH_TOKEN = ""
SENTRY_ORG = "dangeredwolf"
SENTRY_PROJECT = "fixtweet"
SENTRY_ORG = ""
SENTRY_PROJECT = ""

View file

@ -6,6 +6,7 @@
"globals": {
"BRANDING_NAME": "FixTweet",
"BRANDING_NAME_DISCORD": "FixTweetBrandingDiscord",
"TEXT_ONLY_DOMAINS": "t.fxtwitter.com,t.twittpr.com",
"DIRECT_MEDIA_DOMAINS": "d.fxtwitter.com,dl.fxtwitter.com",
"MOSAIC_DOMAIN_LIST": "mosaic.fxtwitter.com",
"DEPRECATED_DOMAIN_LIST": "pxtwitter.com,www.pxtwitter.com",

View file

@ -3,6 +3,7 @@ export const Constants = {
BRANDING_NAME: BRANDING_NAME,
BRANDING_NAME_DISCORD: BRANDING_NAME_DISCORD,
DIRECT_MEDIA_DOMAINS: DIRECT_MEDIA_DOMAINS.split(','),
TEXT_ONLY_DOMAINS: TEXT_ONLY_DOMAINS.split(','),
DEPRECATED_DOMAIN_LIST: DEPRECATED_DOMAIN_LIST.split(','),
DEPRECATED_DOMAIN_EPOCH: BigInt(DEPRECATED_DOMAIN_EPOCH),
MOSAIC_DOMAIN_LIST: MOSAIC_DOMAIN_LIST.split(','),

View file

@ -48,6 +48,9 @@ const statusRequest = async (
} else if (Constants.DIRECT_MEDIA_DOMAINS.includes(url.hostname)) {
console.log('Direct media request by domain');
flags.direct = true;
} else if (Constants.TEXT_ONLY_DOMAINS.includes(url.hostname)) {
console.log('Text-only embed request');
flags.textOnly = true;
} else if (prefix === 'dl' || prefix === 'dir') {
console.log('Direct media request by path prefix');
flags.direct = true;

View file

@ -74,6 +74,10 @@ export const handleStatus = async (
tweet.twitter_card = tweet.quote.twitter_card;
}
if (flags?.textOnly) {
tweet.media = undefined;
}
/* At this point, we know we're going to have to create a
regular embed because it's not an API or direct media request */
@ -292,7 +296,7 @@ export const handleStatus = async (
}
/* If we have no media to display, instead we'll display the user profile picture in the embed */
if (!tweet.media?.video && !tweet.media?.photos) {
if (!tweet.media?.video && !tweet.media?.photos && !flags?.textOnly) {
headers.push(
/* Use a slightly higher resolution image for profile pics */
`<meta property="og:image" content="${tweet.author.avatar_url?.replace(

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

@ -1,6 +1,7 @@
declare const BRANDING_NAME: string;
declare const BRANDING_NAME_DISCORD: string;
declare const DIRECT_MEDIA_DOMAINS: string;
declare const TEXT_ONLY_DOMAINS: string;
declare const DEPRECATED_DOMAIN_LIST: string;
declare const DEPRECATED_DOMAIN_EPOCH: string;
declare const HOST_URL: string;

View file

@ -6,6 +6,7 @@ type InputFlags = {
direct?: boolean;
api?: boolean;
deprecated?: boolean;
textOnly?: boolean;
};
interface StatusResponse {

View file

@ -21,6 +21,7 @@ let envVariables = [
'BRANDING_NAME',
'BRANDING_NAME_DISCORD',
'DIRECT_MEDIA_DOMAINS',
'TEXT_ONLY_DOMAINS',
'HOST_URL',
'REDIRECT_URL',
'EMBED_URL',