mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-05 10:30:55 +01:00
Tweaks to oembed and gallery view
This commit is contained in:
parent
2d5198ef5c
commit
95200b3f65
4 changed files with 25 additions and 9 deletions
|
@ -102,6 +102,7 @@ export const handleStatus = async (
|
||||||
let useIV =
|
let useIV =
|
||||||
isTelegram /*&& !tweet.possibly_sensitive*/ &&
|
isTelegram /*&& !tweet.possibly_sensitive*/ &&
|
||||||
!flags?.direct &&
|
!flags?.direct &&
|
||||||
|
!flags?.gallery &&
|
||||||
!flags?.api &&
|
!flags?.api &&
|
||||||
(tweet.media?.photos?.[0] || // Force instant view for photos for now https://bugs.telegram.org/c/33679
|
(tweet.media?.photos?.[0] || // Force instant view for photos for now https://bugs.telegram.org/c/33679
|
||||||
tweet.media?.mosaic ||
|
tweet.media?.mosaic ||
|
||||||
|
@ -402,15 +403,19 @@ export const handleStatus = async (
|
||||||
|
|
||||||
/* 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="twitter:card" content="${useCard}"/>`
|
`<meta property="twitter:card" content="${useCard}"/>`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!flags.gallery) {
|
if (!flags.gallery) {
|
||||||
headers.push(
|
headers.push(
|
||||||
|
`<meta property="og:title" content="${tweet.author.name} (@${tweet.author.screen_name})"/>`,
|
||||||
`<meta property="og:description" content="${text}"/>`,
|
`<meta property="og:description" content="${text}"/>`,
|
||||||
`<meta property="og:site_name" content="${siteName}"/>`,
|
`<meta property="og:site_name" content="${siteName}"/>`,
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
headers.push(
|
||||||
|
`<meta property="og:title" content="${tweet.author.name}"/>`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Special reply handling if authorText is not overriden */
|
/* Special reply handling if authorText is not overriden */
|
||||||
|
@ -431,10 +436,10 @@ export const handleStatus = async (
|
||||||
`<link rel="alternate" href="{base}/owoembed?text={text}{deprecatedFlag}&status={status}&author={author}" type="application/json+oembed" title="{name}">`.format(
|
`<link rel="alternate" href="{base}/owoembed?text={text}{deprecatedFlag}&status={status}&author={author}" type="application/json+oembed" title="{name}">`.format(
|
||||||
{
|
{
|
||||||
base: Constants.HOST_URL,
|
base: Constants.HOST_URL,
|
||||||
text: encodeURIComponent(truncateWithEllipsis(authorText, 255)),
|
text: flags.gallery ? tweet.author.name : encodeURIComponent(truncateWithEllipsis(authorText, 255)),
|
||||||
deprecatedFlag: flags?.deprecated ? '&deprecated=true' : '',
|
deprecatedFlag: flags?.deprecated ? '&deprecated=true' : '',
|
||||||
status: encodeURIComponent(status),
|
status: encodeURIComponent(status),
|
||||||
author: encodeURIComponent(tweet.author?.screen_name || ''),
|
author: encodeURIComponent(tweet.author.screen_name || ''),
|
||||||
name: tweet.author.name || ''
|
name: tweet.author.name || ''
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -98,6 +98,7 @@ twitter.get(
|
||||||
twitter.get('/version/', versionRoute);
|
twitter.get('/version/', versionRoute);
|
||||||
twitter.get('/version', versionRoute);
|
twitter.get('/version', versionRoute);
|
||||||
twitter.get('/set_base_redirect', setRedirectRequest);
|
twitter.get('/set_base_redirect', setRedirectRequest);
|
||||||
|
/* Yes, I actually made the endpoint /owoembed. Deal with it. */
|
||||||
twitter.get('/owoembed', oembed);
|
twitter.get('/owoembed', oembed);
|
||||||
|
|
||||||
twitter.get('/robots.txt', async c => c.text(Strings.ROBOTS_TXT));
|
twitter.get('/robots.txt', async c => c.text(Strings.ROBOTS_TXT));
|
||||||
|
|
|
@ -3,20 +3,19 @@ import motd from '../../../../motd.json';
|
||||||
import { Constants } from '../../../constants';
|
import { Constants } from '../../../constants';
|
||||||
import { Strings } from '../../../strings';
|
import { Strings } from '../../../strings';
|
||||||
|
|
||||||
/* Yes, I actually made the endpoint /owoembed. Deal with it. */
|
|
||||||
export const oembed = async (c: Context) => {
|
export const oembed = async (c: Context) => {
|
||||||
console.log('oembed hit!');
|
console.log('oembed hit!');
|
||||||
const { searchParams } = new URL(c.req.url);
|
const { searchParams } = new URL(c.req.url);
|
||||||
|
|
||||||
/* Fallbacks */
|
/* Fallbacks */
|
||||||
const text = searchParams.get('text') || 'Twitter';
|
const text = searchParams.get('text') ?? 'Twitter';
|
||||||
const author = searchParams.get('author') || 'jack';
|
const author = searchParams.get('author') ?? 'jack';
|
||||||
const status = searchParams.get('status') || '20';
|
const status = searchParams.get('status') ?? '20';
|
||||||
|
|
||||||
const random = Math.floor(Math.random() * Object.keys(motd).length);
|
const random = Math.floor(Math.random() * Object.keys(motd).length);
|
||||||
const [name, url] = Object.entries(motd)[random];
|
const [name, url] = Object.entries(motd)[random];
|
||||||
|
|
||||||
const test = {
|
const data: OEmbed = {
|
||||||
author_name: text,
|
author_name: text,
|
||||||
author_url: `${Constants.TWITTER_ROOT}/${encodeURIComponent(author)}/status/${status}`,
|
author_url: `${Constants.TWITTER_ROOT}/${encodeURIComponent(author)}/status/${status}`,
|
||||||
/* Change provider name if tweet is on deprecated domain. */
|
/* Change provider name if tweet is on deprecated domain. */
|
||||||
|
@ -27,8 +26,9 @@ export const oembed = async (c: Context) => {
|
||||||
type: 'link',
|
type: 'link',
|
||||||
version: '1.0'
|
version: '1.0'
|
||||||
};
|
};
|
||||||
|
|
||||||
c.header('content-type', 'application/json');
|
c.header('content-type', 'application/json');
|
||||||
c.status(200);
|
c.status(200);
|
||||||
/* Stringify and send it on its way! */
|
/* Stringify and send it on its way! */
|
||||||
return c.text(JSON.stringify(test));
|
return c.text(JSON.stringify(data));
|
||||||
};
|
};
|
||||||
|
|
10
src/types/types.d.ts
vendored
10
src/types/types.d.ts
vendored
|
@ -197,3 +197,13 @@ interface SocialThread {
|
||||||
interface FetchResults {
|
interface FetchResults {
|
||||||
status: number;
|
status: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface OEmbed {
|
||||||
|
author_name?: string;
|
||||||
|
author_url?: string;
|
||||||
|
provider_name?: string;
|
||||||
|
provider_url?: string;
|
||||||
|
title?: string | null;
|
||||||
|
type: 'link';
|
||||||
|
version: '1.0';
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue