mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-05 10:30:55 +01:00
Minor improvements
This commit is contained in:
parent
2b36366c3d
commit
f939712635
4 changed files with 39 additions and 35 deletions
|
@ -117,7 +117,7 @@ const populateTweetProperties = async (
|
|||
}
|
||||
|
||||
/* Handle photos and mosaic if available */
|
||||
if ((apiTweet.media?.photos?.length || 0) > 1) {
|
||||
if ((apiTweet?.media?.photos?.length || 0) > 1) {
|
||||
const mosaic = await handleMosaic(apiTweet.media?.photos || [], tweet.rest_id);
|
||||
if (typeof apiTweet.media !== 'undefined' && mosaic !== null) {
|
||||
apiTweet.media.mosaic = mosaic;
|
||||
|
|
|
@ -38,7 +38,7 @@ export const handleStatus = async (
|
|||
|
||||
const isTelegram = (userAgent || '').indexOf('Telegram') > -1;
|
||||
/* Should sensitive posts be allowed Instant View? */
|
||||
const useIV =
|
||||
let useIV =
|
||||
isTelegram /*&& !tweet.possibly_sensitive*/ &&
|
||||
!flags?.direct &&
|
||||
!flags?.api &&
|
||||
|
@ -130,12 +130,17 @@ export const handleStatus = async (
|
|||
}
|
||||
|
||||
if (useIV) {
|
||||
try {
|
||||
const instructions = renderInstantView({ tweet: tweet, text: newText });
|
||||
headers.push(...instructions.addHeaders);
|
||||
if (instructions.authorText) {
|
||||
authorText = instructions.authorText;
|
||||
}
|
||||
ivbody = instructions.text || '';
|
||||
} catch (e) {
|
||||
console.log('Error rendering Instant View', e);
|
||||
useIV = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* This Tweet has a translation attached to it, so we'll render it. */
|
||||
|
@ -365,7 +370,7 @@ export const handleStatus = async (
|
|||
lang: `lang="${lang}"`,
|
||||
headers: headers.join(''),
|
||||
body: ivbody
|
||||
}),
|
||||
}).replace(/>(\s+)</gm, '><'), // Remove whitespace between tags
|
||||
cacheControl: cacheControl
|
||||
};
|
||||
};
|
||||
|
|
|
@ -21,13 +21,13 @@ const generateTweetMedia = (tweet: APITweet): string => {
|
|||
tweet.media.all.forEach(mediaItem => {
|
||||
switch (mediaItem.type) {
|
||||
case 'photo':
|
||||
media += `<img src="${mediaItem.url}" alt="${tweet.author.name}'s photo" />`;
|
||||
media += `<img src="${mediaItem.url}" alt="${tweet.author.name}'s photo"/>`;
|
||||
break;
|
||||
case 'video':
|
||||
media += `<video src="${mediaItem.url}" alt="${tweet.author.name}'s video" />`;
|
||||
media += `<video src="${mediaItem.url}" alt="${tweet.author.name}'s video"/>`;
|
||||
break;
|
||||
case 'gif':
|
||||
media += `<video src="${mediaItem.url}" alt="${tweet.author.name}'s gif" />`;
|
||||
media += `<video src="${mediaItem.url}" alt="${tweet.author.name}'s gif"/>`;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
@ -91,6 +91,7 @@ function getTranslatedText(tweet: APITweet, isQuote = false): string | null {
|
|||
return `<h4>${formatText}</h4>${text}<h4>Original</h4>`;
|
||||
}
|
||||
|
||||
const notApplicableComment = '<!-- N/A -->';
|
||||
/* TODO: maybe refactor so all tweets pull from this */
|
||||
const generateTweet = (tweet: APITweet, isQuote = false): string => {
|
||||
let text = paragraphify(sanitizeText(tweet.text), isQuote);
|
||||
|
@ -100,7 +101,7 @@ const generateTweet = (tweet: APITweet, isQuote = false): string => {
|
|||
|
||||
const translatedText = getTranslatedText(tweet, isQuote);
|
||||
|
||||
return `
|
||||
return `<!-- Telegram Instant View -->
|
||||
<!-- Embed profile picture, display name, and screen name in table -->
|
||||
${
|
||||
!isQuote
|
||||
|
@ -120,12 +121,15 @@ const generateTweet = (tweet: APITweet, isQuote = false): string => {
|
|||
`
|
||||
: ''
|
||||
}
|
||||
<!-- Translated text (if applicable) -->
|
||||
${translatedText ? translatedText : notApplicableComment}
|
||||
<!-- Embed Tweet text -->
|
||||
${translatedText ? translatedText : ''}
|
||||
${text}
|
||||
<!-- Embed Tweet media -->
|
||||
${generateTweetMedia(tweet)}
|
||||
${!isQuote && tweet.quote ? generateTweet(tweet.quote, true) : ''}
|
||||
<br>${!isQuote ? `<a href="${tweet.url}">View original</a>` : ''}
|
||||
<!-- Embedded quote tweet -->
|
||||
${!isQuote && tweet.quote ? generateTweet(tweet.quote, true) : notApplicableComment}
|
||||
<br>${!isQuote ? `<a href="${tweet.url}">View original</a>` : notApplicableComment}
|
||||
`;
|
||||
};
|
||||
|
||||
|
@ -150,8 +154,8 @@ export const renderInstantView = (properties: RenderProperties): ResponseInstruc
|
|||
<section class="section-backgroundImage">
|
||||
<figure class="graf--layoutFillWidth"></figure>
|
||||
</section>
|
||||
<section class="section--first" style="font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-size: 64px;">
|
||||
If you can see this, your browser is doing something weird with your user agent. <a href="${
|
||||
<section class="section--first" style="font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-size: 64px;">${''
|
||||
}If you can see this, your browser is doing something weird with your user agent.<a href="${
|
||||
tweet.url
|
||||
}">View original post</a>
|
||||
</section>
|
||||
|
@ -159,13 +163,8 @@ export const renderInstantView = (properties: RenderProperties): ResponseInstruc
|
|||
<h1>${tweet.author.name} (@${tweet.author.screen_name})</h1>
|
||||
<p>Instant View (✨ Beta) - <a href="${tweet.url}">View original</a></p>
|
||||
|
||||
<!--blockquote class="twitter-tweet" data-dnt="true"><p lang="en" dir="ltr"> <a href="${
|
||||
tweet.url
|
||||
}">_</a></blockquote-->
|
||||
|
||||
${generateTweet(tweet)}
|
||||
</article>
|
||||
`;
|
||||
</article>`
|
||||
|
||||
return instructions;
|
||||
};
|
||||
|
|
|
@ -64,7 +64,7 @@ This is caused by Twitter API downtime or a new bug. Try again in a little while
|
|||
</body>
|
||||
</html>`
|
||||
.replace(/( {2})/g, '')
|
||||
.replace(/>[\s|\n]+</g, '><'),
|
||||
.replace(/>\s+</gm, '><'),
|
||||
VERSION_HTML: `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
@ -125,7 +125,7 @@ This is caused by Twitter API downtime or a new bug. Try again in a little while
|
|||
</body>
|
||||
</html>`
|
||||
.replace(/( {2})/g, '')
|
||||
.replace(/>[\s|\n]+</g, '><'),
|
||||
.replace(/>\s+</gm, '><'),
|
||||
DEFAULT_AUTHOR_TEXT: 'Twitter',
|
||||
|
||||
QUOTE_TEXT: `↘️ Quoting {name} (@{screen_name})`,
|
||||
|
|
Loading…
Add table
Reference in a new issue