diff --git a/src/embed/status.ts b/src/embed/status.ts index b17441d..9f653ea 100644 --- a/src/embed/status.ts +++ b/src/embed/status.ts @@ -48,6 +48,11 @@ export const handleStatus = async ( tweet.translation || flags?.forceInstantView); + /* Force enable IV for archivers */ + if (flags?.archive) { + useIV = true; + } + let ivbody = ''; /* Catch this request if it's an API response */ @@ -136,7 +141,11 @@ export const handleStatus = async ( if (useIV) { try { - const instructions = renderInstantView({ tweet: tweet, text: newText }); + const instructions = renderInstantView({ + tweet: tweet, + text: newText, + flags: flags + }); headers.push(...instructions.addHeaders); if (instructions.authorText) { authorText = instructions.authorText; diff --git a/src/render/instantview.ts b/src/render/instantview.ts index 98e99b7..53f19a3 100644 --- a/src/render/instantview.ts +++ b/src/render/instantview.ts @@ -130,7 +130,7 @@ const generateTweetFooter = (tweet: APITweet, isQuote = false): string => {

About author

${ !isQuote - ? ` + ? ` ${
         author.name
       }'s profile picture @@ -144,8 +144,7 @@ const generateTweetFooter = (tweet: APITweet, isQuote = false): string => { }${' '}${author.joined ? `📆 ${formatDate(new Date(author.joined))}` : ''}

${truncateSocialCount(author.following)} Following  ${truncateSocialCount(author.followers)} Followers  - ${truncateSocialCount(author.tweets)} Posts

-
` + ${truncateSocialCount(author.tweets)} Posts

` : '' }`; }; @@ -182,7 +181,7 @@ const generateTweet = (tweet: APITweet, isQuote = false): string => { export const renderInstantView = (properties: RenderProperties): ResponseInstructions => { console.log('Generating Instant View...'); - const { tweet } = properties; + const { tweet, flags } = properties; const instructions: ResponseInstructions = { addHeaders: [] }; /* Use ISO date for Medium template */ const postDate = new Date(tweet.created_at).toISOString(); @@ -194,16 +193,21 @@ export const renderInstantView = (properties: RenderProperties): ResponseInstruc contact me https://t.me/dangeredwolf */ instructions.addHeaders = [ ``, - `` + ``, + flags?.archive + ? `` + : `` ]; instructions.text = `
-
${''}If you can see this, your browser is doing something weird with your user agent.View original post +
${ + flags?.archive + ? `${Constants.BRANDING_NAME} archive` + : 'If you can see this, your browser is doing something weird with your user agent.' + } View original post

${tweet.author.name} (@${tweet.author.screen_name})

diff --git a/src/server.ts b/src/server.ts index ccf5041..226f9b2 100644 --- a/src/server.ts +++ b/src/server.ts @@ -22,6 +22,16 @@ const statusRequest = async ( // eslint-disable-next-line sonarjs/no-duplicate-string const userAgent = request.headers.get('User-Agent') || ''; + /* Let's return our HTML version for wayback machine (we can add other archivers too in future) */ + if ( + ['archive.org', 'Wayback Machine'].some(service => + request.headers.get('Via').includes(service) + ) + ) { + console.log('Request from archive.org'); + flags.archive = true; + } + /* User Agent matching for embed generators, bots, crawlers, and other automated tools. It's pretty all-encompassing. Note that Firefox/92 is in here because Discord sometimes uses the following UA: @@ -33,7 +43,7 @@ const statusRequest = async ( On the very rare off chance someone happens to be using specifically Firefox 92, the http-equiv="refresh" meta tag will ensure an actual human is sent to the destination. */ - const isBotUA = userAgent.match(Constants.BOT_UA_REGEX) !== null; + const isBotUA = userAgent.match(Constants.BOT_UA_REGEX) !== null || flags?.archive; /* Check if domain is a direct media domain (i.e. d.fxtwitter.com), the tweet is prefixed with /dl/ or /dir/ (for TwitFix interop), or the diff --git a/src/types/types.d.ts b/src/types/types.d.ts index 185861d..d6f9f7f 100644 --- a/src/types/types.d.ts +++ b/src/types/types.d.ts @@ -9,6 +9,7 @@ type InputFlags = { textOnly?: boolean; isXDomain?: boolean; forceInstantView?: boolean; + archive?: boolean; }; interface StatusResponse { @@ -33,6 +34,7 @@ interface RenderProperties { isOverrideMedia?: boolean; userAgent?: string; text?: string; + flags?: InputFlags; } interface Request {