mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-13 06:11:00 +01:00
Add gallery flag (#462)
This commit is contained in:
parent
9da7927c13
commit
2d5198ef5c
8 changed files with 51 additions and 24 deletions
|
@ -1,8 +1,9 @@
|
||||||
BRANDING_NAME = "FixTweet / FixupX"
|
BRANDING_NAME = "FixTweet / FixupX"
|
||||||
STANDARD_DOMAIN_LIST = "fxtwitter.com,fixupx.com,twittpr.com"
|
STANDARD_DOMAIN_LIST = "fxtwitter.com,fixupx.com,twittpr.com"
|
||||||
DIRECT_MEDIA_DOMAINS = "d.fxtwitter.com,dl.fxtwitter.com,d.pxtwitter.com,d.twittpr.com,dl.pxtwitter.com,dl.twittpr.com,d.fixupx.com,d.xfixup.com,dl.fixupx.com,dl.xfixup.com"
|
DIRECT_MEDIA_DOMAINS = "d.fxtwitter.com,dl.fxtwitter.com,d.pxtwitter.com,d.twittpr.com,dl.pxtwitter.com,dl.twittpr.com,d.fixupx.com,d.xfixup.com,dl.fixupx.com,dl.xfixup.com"
|
||||||
TEXT_ONLY_DOMAINS = "t.fxtwitter.com,t.twittpr.com,t.fixupx.com,t.xfixup.com"
|
TEXT_ONLY_DOMAINS = "t.fxtwitter.com,t.twittpr.com,t.fixupx.com"
|
||||||
INSTANT_VIEW_DOMAINS = "i.fxtwitter.com,i.twittpr.com,i.fixupx.com,i.xfixup.com"
|
INSTANT_VIEW_DOMAINS = "i.fxtwitter.com,i.twittpr.com,i.fixupx.com"
|
||||||
|
GALLERY_DOMAINS = "g.fxtwitter.com,g.twittpr.com,g.fixupx.com"
|
||||||
DEPRECATED_DOMAIN_LIST = "pxtwitter.com,www.pxtwitter.com"
|
DEPRECATED_DOMAIN_LIST = "pxtwitter.com,www.pxtwitter.com"
|
||||||
DEPRECATED_DOMAIN_EPOCH = "1559320000000000000"
|
DEPRECATED_DOMAIN_EPOCH = "1559320000000000000"
|
||||||
MOSAIC_DOMAIN_LIST = "mosaic.fxtwitter.com"
|
MOSAIC_DOMAIN_LIST = "mosaic.fxtwitter.com"
|
||||||
|
|
|
@ -37,6 +37,7 @@ let envVariables = [
|
||||||
'DIRECT_MEDIA_DOMAINS',
|
'DIRECT_MEDIA_DOMAINS',
|
||||||
'TEXT_ONLY_DOMAINS',
|
'TEXT_ONLY_DOMAINS',
|
||||||
'INSTANT_VIEW_DOMAINS',
|
'INSTANT_VIEW_DOMAINS',
|
||||||
|
'GALLERY_DOMAINS',
|
||||||
'HOST_URL',
|
'HOST_URL',
|
||||||
'REDIRECT_URL',
|
'REDIRECT_URL',
|
||||||
'EMBED_URL',
|
'EMBED_URL',
|
||||||
|
|
|
@ -5,10 +5,11 @@
|
||||||
},
|
},
|
||||||
"globals": {
|
"globals": {
|
||||||
"BRANDING_NAME": "FixTweet",
|
"BRANDING_NAME": "FixTweet",
|
||||||
"TEXT_ONLY_DOMAINS": "t.fxtwitter.com,t.twittpr.com",
|
"TEXT_ONLY_DOMAINS": "t.fxtwitter.com,t.twittpr.com,t.fixupx.com",
|
||||||
"INSTANT_VIEW_DOMAINS": "i.fxtwitter.com,i.twittpr.com",
|
"INSTANT_VIEW_DOMAINS": "i.fxtwitter.com,i.twittpr.com,i.fixupx.com",
|
||||||
|
"GALLERY_DOMAINS": "g.fxtwitter.com,g.twittpr.com,g.fixupx.com",
|
||||||
"STANDARD_DOMAIN_LIST": "fxtwitter.com,fixupx.com,twittpr.com",
|
"STANDARD_DOMAIN_LIST": "fxtwitter.com,fixupx.com,twittpr.com",
|
||||||
"DIRECT_MEDIA_DOMAINS": "d.fxtwitter.com,dl.fxtwitter.com",
|
"DIRECT_MEDIA_DOMAINS": "d.fxtwitter.com,dl.fxtwitter.com,d.fixupx.com,dl.fixupx.com",
|
||||||
"MOSAIC_DOMAIN_LIST": "mosaic.fxtwitter.com",
|
"MOSAIC_DOMAIN_LIST": "mosaic.fxtwitter.com",
|
||||||
"DEPRECATED_DOMAIN_LIST": "pxtwitter.com,www.pxtwitter.com",
|
"DEPRECATED_DOMAIN_LIST": "pxtwitter.com,www.pxtwitter.com",
|
||||||
"DEPRECATED_DOMAIN_EPOCH": "1559320000000000000",
|
"DEPRECATED_DOMAIN_EPOCH": "1559320000000000000",
|
||||||
|
|
|
@ -5,6 +5,7 @@ export const Constants = {
|
||||||
DIRECT_MEDIA_DOMAINS: DIRECT_MEDIA_DOMAINS.split(','),
|
DIRECT_MEDIA_DOMAINS: DIRECT_MEDIA_DOMAINS.split(','),
|
||||||
TEXT_ONLY_DOMAINS: TEXT_ONLY_DOMAINS.split(','),
|
TEXT_ONLY_DOMAINS: TEXT_ONLY_DOMAINS.split(','),
|
||||||
INSTANT_VIEW_DOMAINS: INSTANT_VIEW_DOMAINS.split(','),
|
INSTANT_VIEW_DOMAINS: INSTANT_VIEW_DOMAINS.split(','),
|
||||||
|
GALLERY_DOMAINS: GALLERY_DOMAINS.split(','),
|
||||||
DEPRECATED_DOMAIN_LIST: DEPRECATED_DOMAIN_LIST.split(','),
|
DEPRECATED_DOMAIN_LIST: DEPRECATED_DOMAIN_LIST.split(','),
|
||||||
DEPRECATED_DOMAIN_EPOCH: BigInt(DEPRECATED_DOMAIN_EPOCH),
|
DEPRECATED_DOMAIN_EPOCH: BigInt(DEPRECATED_DOMAIN_EPOCH),
|
||||||
MOSAIC_DOMAIN_LIST: MOSAIC_DOMAIN_LIST.split(','),
|
MOSAIC_DOMAIN_LIST: MOSAIC_DOMAIN_LIST.split(','),
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { Context } from 'hono';
|
||||||
import { Constants } from '../constants';
|
import { Constants } from '../constants';
|
||||||
import { handleQuote } from '../helpers/quote';
|
import { handleQuote } from '../helpers/quote';
|
||||||
import { formatNumber, sanitizeText, truncateWithEllipsis } from '../helpers/utils';
|
import { formatNumber, sanitizeText, truncateWithEllipsis } from '../helpers/utils';
|
||||||
|
@ -7,7 +8,6 @@ import { renderPhoto } from '../render/photo';
|
||||||
import { renderVideo } from '../render/video';
|
import { renderVideo } from '../render/video';
|
||||||
import { renderInstantView } from '../render/instantview';
|
import { renderInstantView } from '../render/instantview';
|
||||||
import { constructTwitterThread } from '../providers/twitter/conversation';
|
import { constructTwitterThread } from '../providers/twitter/conversation';
|
||||||
import { Context } from 'hono';
|
|
||||||
|
|
||||||
export const returnError = (c: Context, error: string): Response => {
|
export const returnError = (c: Context, error: string): Response => {
|
||||||
return c.text(
|
return c.text(
|
||||||
|
@ -148,6 +148,11 @@ export const handleStatus = async (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* User requested gallery view, but this isn't a post with media */
|
||||||
|
if (flags.gallery && (tweet.media?.all?.length ?? 0) < 1) {
|
||||||
|
flags.gallery = false;
|
||||||
|
}
|
||||||
|
|
||||||
/* At this point, we know we're going to have to create a
|
/* 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 */
|
regular embed because it's not an API or direct media request */
|
||||||
|
|
||||||
|
@ -160,12 +165,17 @@ export const handleStatus = async (
|
||||||
const headers = [
|
const headers = [
|
||||||
`<link rel="canonical" href="${Constants.TWITTER_ROOT}/${tweet.author.screen_name}/status/${tweet.id}"/>`,
|
`<link rel="canonical" href="${Constants.TWITTER_ROOT}/${tweet.author.screen_name}/status/${tweet.id}"/>`,
|
||||||
`<meta property="og:url" content="${Constants.TWITTER_ROOT}/${tweet.author.screen_name}/status/${tweet.id}"/>`,
|
`<meta property="og:url" content="${Constants.TWITTER_ROOT}/${tweet.author.screen_name}/status/${tweet.id}"/>`,
|
||||||
`<meta property="theme-color" content="#00a8fc"/>`,
|
|
||||||
`<meta property="twitter:site" content="@${tweet.author.screen_name}"/>`,
|
`<meta property="twitter:site" content="@${tweet.author.screen_name}"/>`,
|
||||||
`<meta property="twitter:creator" content="@${tweet.author.screen_name}"/>`,
|
`<meta property="twitter:creator" content="@${tweet.author.screen_name}"/>`,
|
||||||
`<meta property="twitter:title" content="${tweet.author.name} (@${tweet.author.screen_name})"/>`
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (!flags.gallery) {
|
||||||
|
headers.push(
|
||||||
|
`<meta property="theme-color" content="#00a8fc"/>`,
|
||||||
|
`<meta property="twitter:title" content="${tweet.author.name} (@${tweet.author.screen_name})"/>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/* This little thing ensures if by some miracle a FixTweet embed is loaded in a browser,
|
/* This little thing ensures if by some miracle a FixTweet embed is loaded in a browser,
|
||||||
it will gracefully redirect to the destination instead of just seeing a blank screen.
|
it will gracefully redirect to the destination instead of just seeing a blank screen.
|
||||||
|
|
||||||
|
@ -389,14 +399,20 @@ export const handleStatus = async (
|
||||||
|
|
||||||
const useCard = tweet.embed_card === 'tweet' ? tweet.quote?.embed_card : tweet.embed_card;
|
const useCard = tweet.embed_card === 'tweet' ? tweet.quote?.embed_card : tweet.embed_card;
|
||||||
|
|
||||||
|
|
||||||
/* Push basic headers relating to author, Tweet text, and site name */
|
/* Push basic headers relating to author, Tweet text, and site name */
|
||||||
headers.push(
|
headers.push(
|
||||||
`<meta property="og:title" content="${tweet.author.name} (@${tweet.author.screen_name})"/>`,
|
`<meta property="og:title" content="${tweet.author.name} (@${tweet.author.screen_name})"/>`,
|
||||||
`<meta property="og:description" content="${text}"/>`,
|
|
||||||
`<meta property="og:site_name" content="${siteName}"/>`,
|
|
||||||
`<meta property="twitter:card" content="${useCard}"/>`
|
`<meta property="twitter:card" content="${useCard}"/>`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!flags.gallery) {
|
||||||
|
headers.push(
|
||||||
|
`<meta property="og:description" content="${text}"/>`,
|
||||||
|
`<meta property="og:site_name" content="${siteName}"/>`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/* Special reply handling if authorText is not overriden */
|
/* Special reply handling if authorText is not overriden */
|
||||||
if (tweet.replying_to && authorText === Strings.DEFAULT_AUTHOR_TEXT) {
|
if (tweet.replying_to && authorText === Strings.DEFAULT_AUTHOR_TEXT) {
|
||||||
authorText = `↪ Replying to @${tweet.replying_to.screen_name}`;
|
authorText = `↪ Replying to @${tweet.replying_to.screen_name}`;
|
||||||
|
@ -408,20 +424,22 @@ export const handleStatus = async (
|
||||||
authorText = `↪ A part of @${tweet.author.screen_name}'s thread`;
|
authorText = `↪ A part of @${tweet.author.screen_name}'s thread`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The additional oembed is pulled by Discord to enable improved embeds.
|
if (!flags.gallery) {
|
||||||
Telegram does not use this. */
|
/* The additional oembed is pulled by Discord to enable improved embeds.
|
||||||
headers.push(
|
Telegram does not use this. */
|
||||||
`<link rel="alternate" href="{base}/owoembed?text={text}{deprecatedFlag}&status={status}&author={author}" type="application/json+oembed" title="{name}">`.format(
|
headers.push(
|
||||||
{
|
`<link rel="alternate" href="{base}/owoembed?text={text}{deprecatedFlag}&status={status}&author={author}" type="application/json+oembed" title="{name}">`.format(
|
||||||
base: Constants.HOST_URL,
|
{
|
||||||
text: encodeURIComponent(truncateWithEllipsis(authorText, 255)),
|
base: Constants.HOST_URL,
|
||||||
deprecatedFlag: flags?.deprecated ? '&deprecated=true' : '',
|
text: encodeURIComponent(truncateWithEllipsis(authorText, 255)),
|
||||||
status: encodeURIComponent(status),
|
deprecatedFlag: flags?.deprecated ? '&deprecated=true' : '',
|
||||||
author: encodeURIComponent(tweet.author?.screen_name || ''),
|
status: encodeURIComponent(status),
|
||||||
name: tweet.author.name || ''
|
author: encodeURIComponent(tweet.author?.screen_name || ''),
|
||||||
}
|
name: tweet.author.name || ''
|
||||||
)
|
}
|
||||||
);
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/* When dealing with a Tweet of unknown lang, fall back to en */
|
/* When dealing with a Tweet of unknown lang, fall back to en */
|
||||||
const lang = tweet.lang === null ? 'en' : tweet.lang || 'en';
|
const lang = tweet.lang === null ? 'en' : tweet.lang || 'en';
|
||||||
|
|
|
@ -55,6 +55,9 @@ export const statusRequest = async (c: Context) => {
|
||||||
} else if (Constants.INSTANT_VIEW_DOMAINS.includes(url.hostname)) {
|
} else if (Constants.INSTANT_VIEW_DOMAINS.includes(url.hostname)) {
|
||||||
console.log('Forced instant view request');
|
console.log('Forced instant view request');
|
||||||
flags.forceInstantView = true;
|
flags.forceInstantView = true;
|
||||||
|
} else if (Constants.GALLERY_DOMAINS.includes(url.hostname)) {
|
||||||
|
console.log('Gallery embed request');
|
||||||
|
flags.gallery = true;
|
||||||
} else if (prefix === 'dl' || prefix === 'dir') {
|
} else if (prefix === 'dl' || prefix === 'dir') {
|
||||||
console.log('Direct media request by path prefix');
|
console.log('Direct media request by path prefix');
|
||||||
flags.direct = true;
|
flags.direct = true;
|
||||||
|
|
1
src/types/env.d.ts
vendored
1
src/types/env.d.ts
vendored
|
@ -3,6 +3,7 @@ declare const STANDARD_DOMAIN_LIST: string;
|
||||||
declare const DIRECT_MEDIA_DOMAINS: string;
|
declare const DIRECT_MEDIA_DOMAINS: string;
|
||||||
declare const TEXT_ONLY_DOMAINS: string;
|
declare const TEXT_ONLY_DOMAINS: string;
|
||||||
declare const INSTANT_VIEW_DOMAINS: string;
|
declare const INSTANT_VIEW_DOMAINS: string;
|
||||||
|
declare const GALLERY_DOMAINS: string;
|
||||||
declare const DEPRECATED_DOMAIN_LIST: string;
|
declare const DEPRECATED_DOMAIN_LIST: string;
|
||||||
declare const DEPRECATED_DOMAIN_EPOCH: string;
|
declare const DEPRECATED_DOMAIN_EPOCH: string;
|
||||||
declare const HOST_URL: string;
|
declare const HOST_URL: string;
|
||||||
|
|
1
src/types/types.d.ts
vendored
1
src/types/types.d.ts
vendored
|
@ -10,6 +10,7 @@ type InputFlags = {
|
||||||
isXDomain?: boolean;
|
isXDomain?: boolean;
|
||||||
forceInstantView?: boolean;
|
forceInstantView?: boolean;
|
||||||
archive?: boolean;
|
archive?: boolean;
|
||||||
|
gallery?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface StatusResponse {
|
interface StatusResponse {
|
||||||
|
|
Loading…
Add table
Reference in a new issue