From 832c3c243add56b8e01d9cfcbc8b23a8a0f67cbe Mon Sep 17 00:00:00 2001 From: dangered wolf Date: Sun, 5 Feb 2023 15:30:43 -0500 Subject: [PATCH] Add text-only embeds (Implements #133) --- .env.example | 5 +++-- jestconfig.json | 1 + src/constants.ts | 1 + src/server.ts | 3 +++ src/status.ts | 6 +++++- src/types/env.d.ts | 1 + src/types/types.d.ts | 1 + webpack.config.js | 1 + 8 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 939a439..fb2d5f8 100644 --- a/.env.example +++ b/.env.example @@ -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" \ No newline at end of file +SENTRY_ORG = "" +SENTRY_PROJECT = "" \ No newline at end of file diff --git a/jestconfig.json b/jestconfig.json index 69c6d05..863ec8b 100644 --- a/jestconfig.json +++ b/jestconfig.json @@ -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", diff --git a/src/constants.ts b/src/constants.ts index a0efc5f..306be9d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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(','), diff --git a/src/server.ts b/src/server.ts index 2c09b7b..bd65eb7 100644 --- a/src/server.ts +++ b/src/server.ts @@ -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; diff --git a/src/status.ts b/src/status.ts index 6881d82..9e5a99d 100644 --- a/src/status.ts +++ b/src/status.ts @@ -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 */ `