Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeredwolf committed Aug 13, 2022
1 parent 50be0d6 commit c4b908a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
cache: 'npm'
cache-dependency-path: package-lock.json
- run: npm install
- run: npx webpack && npm test
- run: npx webpack && npm test
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# FixTweet <img src="https://abs-0.twimg.com/emoji/v2/svg/1f527.svg" height="28">
# FixTweet <img src="https://abs-0.twimg.com/emoji/v2/svg/1f527.svg" height="28">

## Embed Twitter videos, polls, translations, & more on Discord and Telegram!

Expand All @@ -11,6 +11,7 @@
### Add `fx` before your Twitter link to make it `fxtwitter.com`

### In a hurry? On Discord, send a Twitter link and type `s/e/p` to make `twittpr.com`.

<img src="https://cdn.discordapp.com/attachments/165560751363325952/1006346785985417307/fixtweet.webp">

## Embed Videos
Expand Down Expand Up @@ -95,22 +96,22 @@ In many ways, FixTweet has richer embeds and does more. Here's a table comparing

| | FixTweet | Twitter default | vxTwitter (BetterTwitFix) | Twxtter (sixFix) |
| --------------------------------------- | :---------------------------------: | :------------------------------: | :-------------------------------------: | :-----------------------------------: |
| Embed Tweets / Images | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Embed profile pictures on text Tweets | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: |
| Embed Twitter Videos | :heavy_check_mark: | :x:¹ | :heavy_check_mark: | :heavy_check_mark: |
| Embed External Videos (YouTube, etc.) | :heavy_check_mark:| :x: | :x:| :x: |
| Embed Tweets / Images | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Embed profile pictures on text Tweets | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: |
| Embed Twitter Videos | :heavy_check_mark: | :x:¹ | :heavy_check_mark: | :heavy_check_mark: |
| Embed External Videos (YouTube, etc.) | :heavy_check_mark:| :x: | :x: | :x: |
| Embed Poll results | :heavy_check_mark: | :x: | :x: | :x: |
| Embed Quote Tweets | :heavy_check_mark: | :x: | :ballot_box_with_check: Without Media | :ballot_box_with_check: Without Media |
| Embed Multiple Images | :heavy_check_mark: | :heavy_minus_sign: Discord Only³ | :ballot_box_with_check: c.vxtwitter.com | :x: |
| Translate Tweets | :heavy_check_mark: | :x: | :x: | :x: |
| Publicly accessible embed index | :x:² | N/A | :x:² | :heavy_check_mark: |
| Publicly accessible embed index | :x:² | N/A | :x:² | :heavy_check_mark: |
| Replace t.co with original links | :heavy_check_mark: | :x: | :x: | :x: |
| Media-based embed colors on Discord | :heavy_check_mark: | :x: | :x: | :x: |
| Redirect to media file (wihout embed) | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: |
| Strip Twitter tracking info on redirect | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: |
| Show retweet, like, reply counts | :heavy_check_mark: | :heavy_minus_sign: Discord Only³ | :ballot_box_with_check: No replies | :ballot_box_with_check: No replies |
| Discord sed replace (`s/`) friendly | :ballot_box_with_check: twittpr.com | N/A | :x: | :heavy_check_mark: |
| Tweet fetch API for Developers | :heavy_check_mark: | N/A | :x: | :heavy_check_mark: |
| Strip Twitter tracking info on redirect | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: |
| Show retweet, like, reply counts | :heavy_check_mark: | :heavy_minus_sign: Discord Only³ | :ballot_box_with_check: No replies | :ballot_box_with_check: No replies |
| Discord sed replace (`s/`) friendly | :ballot_box_with_check: twittpr.com | N/A | :x: | :heavy_check_mark: |
| Tweet fetch API for Developers | :heavy_check_mark: | N/A | :x: | :heavy_check_mark: |

¹ Discord will attempt to embed Twitter's video player, but it is unreliable

Expand Down
6 changes: 5 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ export const cacheWrapper = async (
});
}

if (cacheUrl.pathname.startsWith('/api/') || cacheUrl.pathname.startsWith('/other/') || cacheUrl.pathname.startsWith('/info/')) {
if (
cacheUrl.pathname.startsWith('/api/') ||
cacheUrl.pathname.startsWith('/other/') ||
cacheUrl.pathname.startsWith('/info/')
) {
return new Response(Strings.TWITFIX_API_SUNSET, {
headers: Constants.RESPONSE_HEADERS,
status: 404
Expand Down
17 changes: 8 additions & 9 deletions src/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export const handleStatus = async (
];

if (userAgent?.indexOf('Telegram') === -1) {
headers.push(`<meta http-equiv="refresh" content="0;url=https://twitter.com/${tweet.author.screen_name}/status/${tweet.id}"/>`)
headers.push(
`<meta http-equiv="refresh" content="0;url=https://twitter.com/${tweet.author.screen_name}/status/${tweet.id}"/>`
);
}

if (tweet.translation) {
Expand Down Expand Up @@ -123,12 +125,12 @@ export const handleStatus = async (

headers.push(
`<meta name="twitter:player:stream:content_type" content="${video.format}"/>`,
`<meta name="twitter:player:height" content="${video.height*sizeMultiplier}"/>`,
`<meta name="twitter:player:width" content="${video.width*sizeMultiplier}"/>`,
`<meta name="twitter:player:height" content="${video.height * sizeMultiplier}"/>`,
`<meta name="twitter:player:width" content="${video.width * sizeMultiplier}"/>`,
`<meta name="og:video" content="${video.url}"/>`,
`<meta name="og:video:secure_url" content="${video.url}"/>`,
`<meta name="og:video:height" content="${video.height*sizeMultiplier}"/>`,
`<meta name="og:video:width" content="${video.width*sizeMultiplier}"/>`,
`<meta name="og:video:height" content="${video.height * sizeMultiplier}"/>`,
`<meta name="og:video:width" content="${video.width * sizeMultiplier}"/>`,
`<meta name="og:video:type" content="${video.format}"/>`,
`<meta name="twitter:image" content="0"/>`
);
Expand All @@ -139,10 +141,7 @@ export const handleStatus = async (
const { photos } = tweet.media;
let photo = photos[(mediaNumber || 1) - 1];

if (
typeof mediaNumber !== 'number' &&
tweet.media.mosaic
) {
if (typeof mediaNumber !== 'number' && tweet.media.mosaic) {
photo = {
url:
userAgent?.indexOf('Telegram') === -1
Expand Down
4 changes: 3 additions & 1 deletion src/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,7 @@ This is caused by Twitter API downtime or a new bug. Try again in a little while
ERROR_PRIVATE: `I can't embed Tweets from private accounts, sorry about that :(`,
ERROR_TWEET_NOT_FOUND: `Sorry, that Tweet doesn't exist :(`,
ERROR_UNKNOWN: `Unknown error occurred, sorry about that :(`,
TWITFIX_API_SUNSET: `The original TwitFix API has been sunset. To learn more about the FixTweet API, check out <a href="https://${API_HOST_LIST.split(',')[0]}">${API_HOST_LIST.split(',')[0]}</a>`,
TWITFIX_API_SUNSET: `The original TwitFix API has been sunset. To learn more about the FixTweet API, check out <a href="https://${
API_HOST_LIST.split(',')[0]
}">${API_HOST_LIST.split(',')[0]}</a>`
};
26 changes: 17 additions & 9 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ test('API fetch video Tweet', async () => {
expect(tweet).toBeTruthy();
expect(tweet.url).toEqual('https://twitter.com/Twitter/status/854416760933556224');
expect(tweet.id).toEqual('854416760933556224');
expect(tweet.text).toEqual('Get the sauces ready, #NuggsForCarter has 3 million+ Retweets.');
expect(tweet.text).toEqual(
'Get the sauces ready, #NuggsForCarter has 3 million+ Retweets.'
);
expect(tweet.author.screen_name?.toLowerCase()).toEqual('twitter');
expect(tweet.author.name).toBeTruthy();
expect(tweet.author.avatar_url).toBeTruthy();
Expand All @@ -113,15 +115,16 @@ test('API fetch video Tweet', async () => {
expect(tweet.replying_to).toBeNull();
expect(tweet.media?.video).toBeTruthy();
const video = tweet.media?.video as APIVideo;
expect(video.url).toEqual('https://video.twimg.com/amplify_video/854415175776059393/vid/720x720/dNEi0crU-jA4mTtr.mp4');
expect(video.url).toEqual(
'https://video.twimg.com/amplify_video/854415175776059393/vid/720x720/dNEi0crU-jA4mTtr.mp4'
);
expect(video.thumbnail_url).toEqual('https://pbs.twimg.com/media/C9t-btLVoAEqZI1.jpg');
expect(video.width).toEqual(1596);
expect(video.height).toEqual(1600);
expect(video.format).toEqual("video/mp4");
expect(video.type).toEqual("video");
expect(video.format).toEqual('video/mp4');
expect(video.type).toEqual('video');
});


test('API fetch multi-photo Tweet', async () => {
const result = await cacheWrapper(
new Request('https://api.fxtwitter.com/dangeredwolf/status/1554870933449482240', {
Expand All @@ -137,7 +140,9 @@ test('API fetch multi-photo Tweet', async () => {

const tweet = response.tweet as APITweet;
expect(tweet).toBeTruthy();
expect(tweet.url).toEqual('https://twitter.com/dangeredwolf/status/1554870933449482240');
expect(tweet.url).toEqual(
'https://twitter.com/dangeredwolf/status/1554870933449482240'
);
expect(tweet.id).toEqual('1554870933449482240');
expect(tweet.text).toEqual('4 photos');
expect(tweet.author.screen_name?.toLowerCase()).toEqual('dangeredwolf');
Expand Down Expand Up @@ -167,7 +172,10 @@ test('API fetch multi-photo Tweet', async () => {
const mosaic = tweet.media?.mosaic as APIMosaicPhoto;
expect(mosaic.width).toEqual(1610);
expect(mosaic.height).toEqual(846);
expect(mosaic.formats?.jpeg).toEqual('https://mosaic.fxtwitter.com/jpeg/1554870933449482240/FZQCeMmXwAAOJTt/FZQCl-lWIAMtoW9/FZQCsQPX0AIbY6H/FZQCxmLXEAMST4q');
expect(mosaic.formats?.webp).toEqual('https://mosaic.fxtwitter.com/webp/1554870933449482240/FZQCeMmXwAAOJTt/FZQCl-lWIAMtoW9/FZQCsQPX0AIbY6H/FZQCxmLXEAMST4q');

expect(mosaic.formats?.jpeg).toEqual(
'https://mosaic.fxtwitter.com/jpeg/1554870933449482240/FZQCeMmXwAAOJTt/FZQCl-lWIAMtoW9/FZQCsQPX0AIbY6H/FZQCxmLXEAMST4q'
);
expect(mosaic.formats?.webp).toEqual(
'https://mosaic.fxtwitter.com/webp/1554870933449482240/FZQCeMmXwAAOJTt/FZQCl-lWIAMtoW9/FZQCsQPX0AIbY6H/FZQCxmLXEAMST4q'
);
});

0 comments on commit c4b908a

Please sign in to comment.