mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-10 21:10:54 +01:00
Run prettier
This commit is contained in:
parent
5c5fef873d
commit
46abc24cbf
6 changed files with 49 additions and 32 deletions
14
README.md
14
README.md
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
[](https://github.com/dangeredwolf/pxtwitter/actions/workflows/webpack.yml)
|
[](https://github.com/dangeredwolf/pxtwitter/actions/workflows/webpack.yml)
|
||||||
|
|
||||||
## A TwitFix-like solution written in TypeScript for Cloudflare Workers.
|
## A TwitFix-like solution written in TypeScript for Cloudflare Workers.
|
||||||
|
|
||||||
### Embed videos, polls, and more on Discord, Telegram, and more!
|
### Embed videos, polls, and more on Discord, Telegram, and more!
|
||||||
|
|
||||||
### Just add `px` before `twitter.com`.
|
### Just add `px` before `twitter.com`.
|
||||||
|
|
||||||

|

|
||||||
|
@ -23,14 +24,13 @@
|
||||||
|
|
||||||
Licensed under the permissive MIT license. Feel free to send a pull request!
|
Licensed under the permissive MIT license. Feel free to send a pull request!
|
||||||
|
|
||||||
|
|
||||||
### Things to tackle in the future
|
### Things to tackle in the future
|
||||||
|
|
||||||
* Embed profiles! (and maybe more from Twitter?)
|
- Embed profiles! (and maybe more from Twitter?)
|
||||||
* Combining multiple images together (would be outside CF Worker)
|
- Combining multiple images together (would be outside CF Worker)
|
||||||
* Caching responses (I haven't done this yet as this is still being actively worked on!)
|
- Caching responses (I haven't done this yet as this is still being actively worked on!)
|
||||||
* Caching guest token (So we don't have to bother Twitter for one on every request)
|
- Caching guest token (So we don't have to bother Twitter for one on every request)
|
||||||
|
|
||||||
### Bugs or issues?
|
### Bugs or issues?
|
||||||
|
|
||||||
Feel free to [open an issue](https://github.com/dangeredwolf/pxTwitter/issues), or [ping me on Twitter and I'll see what I can do](https://twitter.com/dangeredwolf).
|
Feel free to [open an issue](https://github.com/dangeredwolf/pxTwitter/issues), or [ping me on Twitter and I'll see what I can do](https://twitter.com/dangeredwolf).
|
||||||
|
|
37
src/card.ts
37
src/card.ts
|
@ -22,7 +22,11 @@ export const calculateTimeLeftString = (date: Date) => {
|
||||||
return daysString || hoursString || minutesString || secondsString || 'Final results';
|
return daysString || hoursString || minutesString || secondsString || 'Final results';
|
||||||
};
|
};
|
||||||
|
|
||||||
export const renderCard = async (card: TweetCard, headers: string[], userAgent: string = ''): Promise<string> => {
|
export const renderCard = async (
|
||||||
|
card: TweetCard,
|
||||||
|
headers: string[],
|
||||||
|
userAgent: string = ''
|
||||||
|
): Promise<string> => {
|
||||||
let str = '\n\n';
|
let str = '\n\n';
|
||||||
const values = card.binding_values;
|
const values = card.binding_values;
|
||||||
|
|
||||||
|
@ -39,8 +43,10 @@ export const renderCard = async (card: TweetCard, headers: string[], userAgent:
|
||||||
|
|
||||||
/* TODO: make poll code cleaner */
|
/* TODO: make poll code cleaner */
|
||||||
if (typeof values !== 'undefined') {
|
if (typeof values !== 'undefined') {
|
||||||
if (typeof values.choice1_count !== 'undefined' &&
|
if (
|
||||||
typeof values.choice2_count !== 'undefined') {
|
typeof values.choice1_count !== 'undefined' &&
|
||||||
|
typeof values.choice2_count !== 'undefined'
|
||||||
|
) {
|
||||||
if (typeof values.end_datetime_utc !== 'undefined') {
|
if (typeof values.end_datetime_utc !== 'undefined') {
|
||||||
const date = new Date(values.end_datetime_utc.string_value);
|
const date = new Date(values.end_datetime_utc.string_value);
|
||||||
timeLeft = calculateTimeLeftString(date);
|
timeLeft = calculateTimeLeftString(date);
|
||||||
|
@ -72,26 +78,33 @@ export const renderCard = async (card: TweetCard, headers: string[], userAgent:
|
||||||
${label} (${Math.round((votes / totalVotes || 0) * 100)}%)
|
${label} (${Math.round((votes / totalVotes || 0) * 100)}%)
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
str += `\n${totalVotes} votes · ${timeLeft}`;
|
str += `\n${totalVotes} votes · ${timeLeft}`;
|
||||||
|
|
||||||
console.log(str);
|
console.log(str);
|
||||||
}
|
}
|
||||||
} else if (typeof values.player_url !== "undefined") {
|
} else if (typeof values.player_url !== 'undefined') {
|
||||||
headers.push(
|
headers.push(
|
||||||
`<meta name="twitter:player" content="${values.player_url.string_value}">`,
|
`<meta name="twitter:player" content="${values.player_url.string_value}">`,
|
||||||
`<meta name="twitter:player:width" content="${values.player_width?.string_value || "1280"}">`,
|
`<meta name="twitter:player:width" content="${
|
||||||
`<meta name="twitter:player:height" content="${values.player_height?.string_value || "720"}">`,
|
values.player_width?.string_value || '1280'
|
||||||
|
}">`,
|
||||||
|
`<meta name="twitter:player:height" content="${
|
||||||
|
values.player_height?.string_value || '720'
|
||||||
|
}">`,
|
||||||
`<meta property="og:type" content="video.other">`,
|
`<meta property="og:type" content="video.other">`,
|
||||||
`<meta property="og:video:url" content="${values.player_url.string_value}">`,
|
`<meta property="og:video:url" content="${values.player_url.string_value}">`,
|
||||||
`<meta property="og:video:secure_url" content="${values.player_url.string_value}">`,
|
`<meta property="og:video:secure_url" content="${values.player_url.string_value}">`,
|
||||||
`<meta property="og:video:type" content="text/html">`,
|
`<meta property="og:video:type" content="text/html">`,
|
||||||
`<meta property="og:video:width" content="${values.player_width?.string_value || "1280"}">`,
|
`<meta property="og:video:width" content="${
|
||||||
`<meta property="og:video:height" content="${values.player_height?.string_value || "720"}">`,
|
values.player_width?.string_value || '1280'
|
||||||
)
|
}">`,
|
||||||
|
`<meta property="og:video:height" content="${
|
||||||
|
values.player_height?.string_value || '720'
|
||||||
|
}">`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,9 +4,9 @@ export const linkFixer = (tweet: TweetPartial, text: string): string => {
|
||||||
tweet.entities?.urls.forEach((url: TcoExpansion) => {
|
tweet.entities?.urls.forEach((url: TcoExpansion) => {
|
||||||
text = text.replace(url.url, url.expanded_url);
|
text = text.replace(url.url, url.expanded_url);
|
||||||
});
|
});
|
||||||
|
|
||||||
text = text.replace(/ ?https\:\/\/t\.co\/\w{10}/, '');
|
text = text.replace(/ ?https\:\/\/t\.co\/\w{10}/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
};
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { linkFixer } from "./linkFixer";
|
import { linkFixer } from './linkFixer';
|
||||||
|
|
||||||
export const handleQuote = (quote: TweetPartial): string | null => {
|
export const handleQuote = (quote: TweetPartial): string | null => {
|
||||||
console.log('quote tweet: ', quote);
|
console.log('quote tweet: ', quote);
|
||||||
|
|
||||||
let str = `\n`
|
let str = `\n`;
|
||||||
str += `↘️ Quoting ${quote.user?.name} (@${quote.user?.screen_name}) `
|
str += `↘️ Quoting ${quote.user?.name} (@${quote.user?.screen_name}) `;
|
||||||
|
|
||||||
str += '═'.repeat(Math.max(60 - str.length, 0))
|
str += '═'.repeat(Math.max(60 - str.length, 0));
|
||||||
|
|
||||||
str += ` \n\n`;
|
str += ` \n\n`;
|
||||||
str += linkFixer(quote, quote.full_text);
|
str += linkFixer(quote, quote.full_text);
|
||||||
|
|
|
@ -69,7 +69,8 @@ export const handleStatus = async (
|
||||||
conversation.globalObjects?.tweets?.[tweet.quoted_status_id_str || '0'] || null;
|
conversation.globalObjects?.tweets?.[tweet.quoted_status_id_str || '0'] || null;
|
||||||
|
|
||||||
if (quoteTweetMaybe) {
|
if (quoteTweetMaybe) {
|
||||||
quoteTweetMaybe.user = conversation?.globalObjects?.users?.[quoteTweetMaybe.user_id_str] || {};
|
quoteTweetMaybe.user =
|
||||||
|
conversation?.globalObjects?.users?.[quoteTweetMaybe.user_id_str] || {};
|
||||||
const quoteText = handleQuote(quoteTweetMaybe);
|
const quoteText = handleQuote(quoteTweetMaybe);
|
||||||
|
|
||||||
console.log('quoteText', quoteText);
|
console.log('quoteText', quoteText);
|
||||||
|
@ -78,15 +79,18 @@ export const handleStatus = async (
|
||||||
text += `\n${quoteText}`;
|
text += `\n${quoteText}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mediaList.length === 0 && (quoteTweetMaybe.extended_entities?.media?.length || quoteTweetMaybe.entities?.media?.length || 0) > 0) {
|
if (
|
||||||
|
mediaList.length === 0 &&
|
||||||
|
(quoteTweetMaybe.extended_entities?.media?.length ||
|
||||||
|
quoteTweetMaybe.entities?.media?.length ||
|
||||||
|
0) > 0
|
||||||
|
) {
|
||||||
console.log('No media in main tweet, maybe we have some media in the quote tweet?');
|
console.log('No media in main tweet, maybe we have some media in the quote tweet?');
|
||||||
mediaList = Array.from(
|
mediaList = Array.from(
|
||||||
quoteTweetMaybe.extended_entities?.media ||
|
quoteTweetMaybe.extended_entities?.media || quoteTweetMaybe.entities?.media || []
|
||||||
quoteTweetMaybe.entities?.media ||
|
|
||||||
[]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('updated mediaList', mediaList)
|
console.log('updated mediaList', mediaList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
export const sanitizeText = (text: string) => {
|
export const sanitizeText = (text: string) => {
|
||||||
return text.replace(/\"/g, '"').replace(/\</g, '<').replace(/\>/g, '>');
|
return text.replace(/\"/g, '"').replace(/\</g, '<').replace(/\>/g, '>');
|
||||||
}
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue