diff --git a/.env.example b/.env.example index 505fdf1..15642c9 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,8 @@ 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" +DEPRECATED_DOMAIN_LIST = "pxtwitter.com,www.pxtwitter.com" +DEPRECATED_DOMAIN_EPOCH = "1559320000000000000" MOSAIC_DOMAIN_LIST = "mosaic.fxtwitter.com" API_HOST_LIST = "api.fxtwitter.com,api-canary.fxtwitter.com" HOST_URL = "https://fxtwitter.com" diff --git a/README.md b/README.md index f3938f1..d937f8b 100644 --- a/README.md +++ b/README.md @@ -173,15 +173,17 @@ Populate Sentry details in your `.env` to use Sentry in your product to catch ex ## Q&A -### What's the difference between `fxtwitter.com`, `pxtwitter.com`, and `twittpr.com`? +### What's the difference between `fxtwitter.com`, `twittpr.com`, and `pxtwitter.com`? -They all run the exact same worker and have no difference to end users... you can use whatever you'd like! +They all run the exact same worker and function identically... mostly. -However, we do consider `fxtwitter.com` to be the primary domain these days, and the public API is only on `api.fxtwitter.com`. +`fxtwitter.com` is the primary domain these days, with `twittpr.com` as an alternative that allows for quick sed replacement. `pxtwitter.com` was our original domain, but we consider to be deprecated now. + +The way we handle this is that on post-deprecation Tweets linked using `pxtwitter.com`, instead of saying "FixTweet", it will have a notice that we've moved to `fxtwitter.com`. The embeds and redirects will still work, and Tweets posted before deprecation will not be unaffected at all, but it will gently encourage people to migrate by applying the notice to newer Tweets. `pxtwitter.com` was our original domain for the project, bought the day before we launched FixTweet (then known as pxTwitter). I was trying to find something memorable and `px` kinda sounds like "pix" or can mean "pixels" which is fitting as a service that can embed images, videos, etc. Not long after, I bought `twittpr.com` because it's easier to do sed replacement with on Discord (`s/e/p`), and because it had a `p` in it, it was sorta related to pxTwitter. They have always functioned identically. -A couple weeks later, I acquired the `fxtwitter.com` domain from RobinUniverse and alongside this rebranded the project as FixTweet and shifted `fxtwitter.com` to be the primary domain instead of `pxtwitter.com`. Like the addition of `twittpr.com` this domain works identically to the others. I wouldn't go as far as to say `pxtwitter.com` is deprecated, but it certainly is the less preferred domain of the 3. +A couple weeks later, I acquired the `fxtwitter.com` domain from RobinUniverse and alongside this rebranded the project as FixTweet and shifted `fxtwitter.com` to be the primary domain instead of `pxtwitter.com`. Like the addition of `twittpr.com` this domain works identically to the others. ### How come embedding takes so long / is not working in Telegram? diff --git a/src/constants.ts b/src/constants.ts index faf278f..5c77e7d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -7,6 +7,8 @@ export const Constants = { BRANDING_NAME: BRANDING_NAME, BRANDING_NAME_DISCORD: BRANDING_NAME_DISCORD, DIRECT_MEDIA_DOMAINS: DIRECT_MEDIA_DOMAINS.split(','), + DEPRECATED_DOMAIN_LIST: DEPRECATED_DOMAIN_LIST.split(','), + DEPRECATED_DOMAIN_EPOCH: BigInt(DEPRECATED_DOMAIN_EPOCH), MOSAIC_DOMAIN_LIST: MOSAIC_DOMAIN_LIST.split(','), API_HOST_LIST: API_HOST_LIST.split(','), HOST_URL: HOST_URL, diff --git a/src/server.ts b/src/server.ts index f76bfc0..9011100 100644 --- a/src/server.ts +++ b/src/server.ts @@ -31,6 +31,14 @@ const statusRequest = async ( flags.direct = true; } + if ( + Constants.DEPRECATED_DOMAIN_LIST.includes(url.hostname) && + BigInt(id) > Constants.DEPRECATED_DOMAIN_EPOCH + ) { + console.log('Request to deprecated domain'); + flags.deprecated = true; + } + if ( url.pathname.match(/\/status(es)?\/\d+\.(json)/g) !== null || Constants.API_HOST_LIST.includes(url.hostname) @@ -118,7 +126,10 @@ router.get('/owoembed', async (request: Request) => { author_url: `${Constants.TWITTER_ROOT}/${encodeURIComponent( author )}/status/${encodeURIComponent(status)}`, - provider_name: Constants.BRANDING_NAME_DISCORD, + provider_name: + searchParams.get('deprecated') === 'true' + ? Strings.DEPRECATED_DOMAIN_NOTICE_DISCORD + : Constants.BRANDING_NAME_DISCORD, provider_url: Constants.EMBED_URL, title: Strings.DEFAULT_AUTHOR_TEXT, type: 'link', diff --git a/src/status.ts b/src/status.ts index 752ba17..d7b9e3d 100644 --- a/src/status.ts +++ b/src/status.ts @@ -81,6 +81,7 @@ export const handleStatus = async ( let siteName = Constants.BRANDING_NAME; let newText = tweet.text; + /* Base headers included in all responses */ const headers = [ ``, ``, @@ -169,7 +170,6 @@ export const handleStatus = async ( /* Push the raw video-related headers */ headers.push( - ``, ``, ``, ``, @@ -290,6 +290,11 @@ export const handleStatus = async ( ); } + /* Notice that user is using deprecated domain */ + if (flags?.deprecated) { + siteName = Strings.DEPRECATED_DOMAIN_NOTICE; + } + /* Push basic headers relating to author, Tweet text, and site name */ headers.push( ``, @@ -310,7 +315,9 @@ export const handleStatus = async ( headers.push( `` ); diff --git a/src/strings.ts b/src/strings.ts index 98bb5c6..6a3638b 100644 --- a/src/strings.ts +++ b/src/strings.ts @@ -86,7 +86,10 @@ This is caused by Twitter API downtime or a new bug. Try again in a little while ERROR_PRIVATE: `I can't embed Tweets from private accounts, sorry about that :(`, ERROR_TWEET_NOT_FOUND: `Sorry, that Tweet doesn't exist :(`, ERROR_UNKNOWN: `Unknown error occurred, sorry about that :(`, + TWITFIX_API_SUNSET: `The original TwitFix API has been sunset. To learn more about the FixTweet API, check out ${API_HOST_LIST.split(',')[0]}` + }">${API_HOST_LIST.split(',')[0]}`, + DEPRECATED_DOMAIN_NOTICE: `We've moved! ➡ fxtwitter.com`, + DEPRECATED_DOMAIN_NOTICE_DISCORD: `We've moved! ➡ fxtwitter.com` }; diff --git a/src/types/env.d.ts b/src/types/env.d.ts index a0a1525..2495662 100644 --- a/src/types/env.d.ts +++ b/src/types/env.d.ts @@ -1,6 +1,8 @@ declare const BRANDING_NAME: string; declare const BRANDING_NAME_DISCORD: string; declare const DIRECT_MEDIA_DOMAINS: string; +declare const DEPRECATED_DOMAIN_LIST: string; +declare const DEPRECATED_DOMAIN_EPOCH: string; declare const HOST_URL: string; declare const EMBED_URL: string; declare const REDIRECT_URL: string; diff --git a/src/types/types.d.ts b/src/types/types.d.ts index 60e7da2..1d0e7fe 100644 --- a/src/types/types.d.ts +++ b/src/types/types.d.ts @@ -5,6 +5,7 @@ type InputFlags = { standard?: boolean; direct?: boolean; api?: boolean; + deprecated?: boolean; }; interface StatusResponse { diff --git a/tsconfig.json b/tsconfig.json index db8cd39..860a7d9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ "allowJs": true, "sourceMap": true, "esModuleInterop": true, - "types": ["@cloudflare/workers-types", "@types/service-worker-mock", "@types/jest"] + "types": ["@cloudflare/workers-types", "@types/jest"] }, "include": ["src"], "exclude": ["node_modules", "dist", "test"] diff --git a/webpack.config.js b/webpack.config.js index 25849ad..36dd717 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -47,6 +47,12 @@ let plugins = [ }), new webpack.DefinePlugin({ RELEASE_NAME: `'${releaseName}'` + }), + new webpack.DefinePlugin({ + DEPRECATED_DOMAIN_LIST: `'${process.env.DEPRECATED_DOMAIN_LIST}'` + }), + new webpack.DefinePlugin({ + DEPRECATED_DOMAIN_EPOCH: `'${process.env.DEPRECATED_DOMAIN_EPOCH}'` }) ];