Skip to content

Commit

Permalink
fix + chore: remove og:description if addDesc is true + prettier
Browse files Browse the repository at this point in the history
also remove test
  • Loading branch information
okdargy committed Aug 31, 2024
1 parent dfac4db commit fec9a58
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# fxTikTok
# fxTikTok

Embed TikTok videos and slideshows on Discord with just `s/i/n`

[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/okdargy/fxtiktok)
Expand All @@ -9,8 +10,8 @@ Embed TikTok videos and slideshows on Discord with just `s/i/n`
<summary>Click here to preview how fxTikTok looks in action</summary>

| <img src="https://raw.githubusercontent.com/okdargy/fxTikTok/master/.github/readme/compare.png" alt="Video Preview" height="400px" /> |
| :--------------------------------------------------------------------------------------------------------------------------------------------: |
| Comparing `tiktok.com` vs. `tnktok.com` embeds on Discord |
| :-----------------------------------------------------------------------------------------------------------------------------------: |
| Comparing `tiktok.com` vs. `tnktok.com` embeds on Discord |

| <img src="https://raw.githubusercontent.com/okdargy/fxTikTok/master/.github/readme/slideshow.png" alt="Slideshow Preview" /> |
| :--------------------------------------------------------------------------------------------------------------------------: |
Expand All @@ -21,12 +22,13 @@ Embed TikTok videos and slideshows on Discord with just `s/i/n`
| Live video embeds |

| <img src="https://raw.githubusercontent.com/okdargy/fxTikTok/master/.github/readme/direct.png" alt="Direct Preview" height="400px" /> |
| :--------------------------------------------------------------------------------------------------------------------: |
| Direct image/video support |
| :-----------------------------------------------------------------------------------------------------------------------------------: |
| Direct image/video support |

</details>

## 📖 Usage
## 📖 Usage

Using fxTikTok is easy on Discord. Fix ugly and unresponsive embeds by sending your TikTok link and then typing `s/i/n`

<details>
Expand Down Expand Up @@ -59,7 +61,6 @@ By default, we put the description into the `og:description` tag, but Discord re

However, we want to give users the option to add it in case it brings additional context to the video. You can change your URL to `a.tnktok.com` to add the description to the top.


| Before | After |
| :--------------------: | :------------------: |
| **www**.t**i**ktok.com | **a**.t**n**ktok.com |
Expand Down
26 changes: 2 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,13 @@ import generateAlternate from './util/generateAlternate'
import { returnHTMLResponse } from './util/responseHelper'

const app = new Hono()

const awemeIdPattern = /^\d{1,19}$/
const awemeLinkPattern = /\/@([\w\d_.]+)\/(video|photo|live)\/?(\d{19})?/

// Credit: https://github.com/FixTweet/FxTwitter/blob/b6564868719473f926c4e7e28ec95059506f69e2/src/constants.ts#L24
const BOT_REGEX =
/bot|facebook|embed|got|firefox\/92|firefox\/38|curl|wget|go-http|yahoo|generator|whatsapp|revoltchat|preview|link|proxy|vkshare|images|analyzer|index|crawl|spider|python|cfnetwork|node|mastodon|http\.rb|ruby|bun\/|fiddler|iframely|steamchaturllookup/i

app.get('/test/:videoId', async (c) => {
const { videoId } = c.req.param()

try {
const videoData = await scrapeVideoData(videoId)

return new Response(JSON.stringify(videoData), {
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
})
} catch (e) {
return new Response((e as Error).message, {
status: 500,
headers: {
'Content-Type': 'text/plain; charset=utf-8'
}
})
}
})

app.get('/', (c) => {
return new Response('', {
status: 302,
Expand Down Expand Up @@ -299,7 +277,7 @@ app.get('/generate/image/:videoId/:imageCount', async (c) => {
headers: {
'Cache-Control': 'no-cache, no-store, must-revalidate'
}
})
})
}

const images = await fetch('https://tikwm.com/api/', {
Expand Down
13 changes: 9 additions & 4 deletions src/templates/pages/VideoResponse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function VideoResponse(data: ItemStruct, addDesc: Boolean): JSX.Element {
title += `❤️ ${formatNumber(data.stats.diggCount.toString())} `
title += `💬 ${formatNumber(data.stats.commentCount.toString())} `
title += `🔁 ${formatNumber(data.stats.shareCount.toString())} `

if (data.imagePost) {
title += `🖼️ ${data.imagePost.images.length.toString()} `
}
Expand Down Expand Up @@ -104,10 +105,14 @@ export function VideoResponse(data: ItemStruct, addDesc: Boolean): JSX.Element {
name: 'og:url',
content: `https://www.tiktok.com/@${data.author.uniqueId}/video/${data.id}`
},
{
name: 'og:description',
content: data.desc
},
...(!addDesc
? [
{
name: 'og:description',
content: data.desc
}
]
: []),
...videoMeta
],
{
Expand Down

0 comments on commit fec9a58

Please sign in to comment.