diff --git a/src/fetch.ts b/src/fetch.ts index 5d719ed..15840f7 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -6,19 +6,12 @@ import { generateUserAgent } from './helpers/useragent'; const API_ATTEMPTS = 3; let wasElongatorDisabled = false; -/* TODO: Figure out why TS globals were broken when not forcing globalThis */ -declare const globalThis: { - fetchCompletedTime: number; -}; - const generateSnowflake = () => { const epoch = 1288834974657n; /* Twitter snowflake epoch */ const timestamp = BigInt(Date.now()) - epoch; return String((timestamp << 22n) | BigInt(Math.floor(Math.random() * 696969))); }; -globalThis.fetchCompletedTime = 0; - export const twitterFetch = async ( c: Context, url: string, @@ -184,7 +177,6 @@ export const twitterFetch = async ( continue; } - globalThis.fetchCompletedTime = performance.now(); if ( !wasElongatorDisabled && diff --git a/src/realms/api/router.ts b/src/realms/api/router.ts index f692ac8..a4fcc2c 100644 --- a/src/realms/api/router.ts +++ b/src/realms/api/router.ts @@ -9,8 +9,8 @@ export const api = new Hono(); /* Current v1 API endpoints. Currently, these still go through the Twitter embed requests. API v2+ won't do this. */ api.get('/status/:id/:language?', statusRequest); api.get('/:handle/status/:id/:language?', statusRequest); +api.get('/robots.txt', async c => c.text(Strings.ROBOTS_TXT_API)); api.get('/:handle', profileRequest); -api.get('/robots.txt', async c => c.text(Strings.ROBOTS_TXT)); -api.all('*', async c => c.redirect(Constants.API_DOCS_URL, 302)); +api.all('*', async c => c.redirect(Constants.API_DOCS_URL, 302)); \ No newline at end of file diff --git a/src/realms/twitter/router.ts b/src/realms/twitter/router.ts index 8f340aa..7976119 100644 --- a/src/realms/twitter/router.ts +++ b/src/realms/twitter/router.ts @@ -30,14 +30,14 @@ export const getBaseRedirectUrl = (c: Context) => { const tweetRequest = async (c: Context) => await statusRequest(c); const _profileRequest = async (c: Context) => await profileRequest(c); -twitter.get('/:prefix?/:handle?/:endpoint{status(es)?}/:id/:language?', tweetRequest); -twitter.get(':handle?/:endpoint{status(es)?}/:id/:language?', tweetRequest); +twitter.get('/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id{[0-9]+}/:language{[a-z]+}?', tweetRequest); +twitter.get('/:prefix{(dir|dl)}/:handle{[0-9a-zA-Z_]+}/status/:id{[0-9]+}/:language{[a-z]+}?', tweetRequest); twitter.get( - '/:prefix?/:handle/:endpoint{status(es)?}/:id/:mediaType{(photos?|videos?)}/:mediaNumber{[1-4]}/:language?', + '/:handle{[0-9a-zA-Z_]+}/status/:id{[0-9]+}/:mediaType{(photos?|videos?)}/:mediaNumber{[1-4]}/:language{[a-z]+}?', tweetRequest ); twitter.get( - '/:handle/:endpoint{status(es)?}/:id/:mediaType{(photos?|videos?)}/:mediaNumber{[1-4]}/:language?', + '/:prefix{(dir|dl)}/:handle{[0-9a-zA-Z_]+}/status/:id{[0-9]+}/:mediaType{(photos?|videos?)}/:mediaNumber{[1-4]}/:language{[a-z]+}?', tweetRequest ); diff --git a/src/realms/twitter/routes/status.ts b/src/realms/twitter/routes/status.ts index 0e7b827..4b4e354 100644 --- a/src/realms/twitter/routes/status.ts +++ b/src/realms/twitter/routes/status.ts @@ -6,7 +6,8 @@ import { Strings } from '../../../strings'; /* Handler for status (Tweet) request */ export const statusRequest = async (c: Context) => { - const { handle, id, mediaNumber, language, prefix } = c.req.param(); + const { prefix, handle, id, mediaNumber, language } = c.req.param(); + console.log('req', JSON.stringify(c.req)) const url = new URL(c.req.url); const flags: InputFlags = {}; diff --git a/src/strings.ts b/src/strings.ts index 98c3eaa..a90b9d4 100644 --- a/src/strings.ts +++ b/src/strings.ts @@ -228,5 +228,7 @@ Disallow: /owoembed/ Allow: /watch?v=dQw4w9WgXcQ # 0100011101101111011011110110010000100000011000100110111101110100`, - X_DOMAIN_NOTICE: 'FixTweet - 🆕 x.com link? Try fixupx.com' + ROBOTS_TXT_API: `# Crawlers should not crawl API endpoints +User-agent: * +Disallow: /` };