Skip to content

Commit

Permalink
fix: expiring profile pictures on live endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
okdargy committed Jul 29, 2024
1 parent ae81644 commit 8e86d8d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Embed TikTok videos and slideshows on Discord with just `s/i/n`
| Slideshow embeds |

| <img src="https://raw.githubusercontent.com/okdargy/fxTikTok/master/.github/readme/live.png" alt="Live Preview" /> |
| :--------------------------------------------------------------------------------------------------------------------------: |
| Live video embeds |
| :----------------------------------------------------------------------------------------------------------------: |
| Live video embeds |

| <img src="https://raw.githubusercontent.com/okdargy/fxTikTok/master/.github/readme/direct.png" alt="Direct Preview" /> |
| :--------------------------------------------------------------------------------------------------------------------: |
Expand Down Expand Up @@ -53,17 +53,17 @@ Don't want all that statistic clutter on your embed and only want the video or i

We check all the boxes for being one of the best TikTok embedding services with many features that others don't have. Here's a table comparing our service, tnktok.com, with the other TikTok embedding services as well as TikTok's default embeds.

| | [tnktok.com](https://www.tnktok.com) | Default TikTok | [tiktxk.com](https://tiktxk.com) | [vxtiktok.com](https://vxtiktok.com) | [tfxktok.com](https://tfxktok.com) |
|---------------------------------------- |--------------------------------------------------- |---------------- |--------------------------------- |------------------------------------------------------------------------------ |------------------------------------ |
| Embed playable videos | ☑️ | | | ☑️ | ☑️ |
| Embed multi-image slideshows | ☑️ | | | [](https://github.com/dylanpdx/vxtiktok/issues/142#issuecomment-2128030983) | ☑️ |
| Embed lives | ☑️ | | | | ☑️ |
| Open source | ☑️ | | ☑️ | ☑️ | |
| Supports direct embeds | [](https://github.com/okdargy/fxTikTok/issues/9) | | | | |
| Shows like, shares, comments | ☑️ | | | ☑️ | ☑️ |
| Removes tracking for redirects | ☑️ | | ☑️ | ☑️ | ☑️ |
| Support for multi-continent short URLs | [☑️](https://github.com/okdargy/fxTikTok/issues/5) | ☑️ | ☑️ | ☑️ | |
| Last commit | [![][tnk]][tnkc] | N/A | [![][txk]][txkc] | [![][vxt]][vxtc] | N/A |
| | [tnktok.com](https://www.tnktok.com) | Default TikTok | [tiktxk.com](https://tiktxk.com) | [vxtiktok.com](https://vxtiktok.com) | [tfxktok.com](https://tfxktok.com) |
| -------------------------------------- | -------------------------------------------------- | -------------- | -------------------------------- | ----------------------------------------------------------------------------- | ---------------------------------- |
| Embed playable videos | ☑️ ||| ☑️ | ☑️ |
| Embed multi-image slideshows | ☑️ ||| [](https://github.com/dylanpdx/vxtiktok/issues/142#issuecomment-2128030983) | ☑️ |
| Embed lives | ☑️ |||| ☑️ |
| Open source | ☑️ || ☑️ | ☑️ ||
| Supports direct embeds | [](https://github.com/okdargy/fxTikTok/issues/9) |||||
| Shows like, shares, comments | ☑️ ||| ☑️ | ☑️ |
| Removes tracking for redirects | ☑️ || ☑️ | ☑️ | ☑️ |
| Support for multi-continent short URLs | [☑️](https://github.com/okdargy/fxTikTok/issues/5) | ☑️ | ☑️ | ☑️ ||
| Last commit | [![][tnk]][tnkc] | N/A | [![][txk]][txkc] | [![][vxt]][vxtc] | N/A |

[tnk]: https://img.shields.io/github/last-commit/okdargy/fxTikTok?label
[tnkc]: https://github.com/okdargy/fxTikTok/commits
Expand Down
31 changes: 28 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ app.get('/generate/video/:videoId', async (c) => {
try {
const data = await scrapeVideoData(videoId)


/*
if (!(data instanceof Error)) {
if(data.video.playAddr) {
Expand Down Expand Up @@ -252,9 +251,9 @@ app.get('/generate/image/:videoId', async (c) => {
const data = await scrapeVideoData(videoId)

if ('imagePost' in data && data.imagePost.images.length > 0 && +index < data.imagePost.images.length) {
return c.redirect(data.imagePost.images[+index].imageURL.urlList[0]);
return c.redirect(data.imagePost.images[+index].imageURL.urlList[0])
} else {
throw new Error('Image not found');
throw new Error('Image not found')
}
} catch (e) {
return new Response((e as Error).message, {
Expand Down Expand Up @@ -301,6 +300,32 @@ app.get('/generate/image/:videoId/:imageCount', async (c) => {
}
})

app.get('/generate/livePic/:author', async (c) => {
const { author } = c.req.param()

try {
const data = await scrapeLiveData(author)

if (data instanceof Error) {
return new Response((data as Error).message, {
status: 500,
headers: {
'Cache-Control': 'no-cache, no-store, must-revalidate'
}
})
}

return c.redirect(data.liveRoomUserInfo.user.avatarLarger)
} catch (e) {
return new Response((e as Error).message, {
status: 500,
headers: {
'Cache-Control': 'no-cache, no-store, must-revalidate'
}
})
}
})

const routes = [
{
path: '/:videoId',
Expand Down
9 changes: 5 additions & 4 deletions src/templates/pages/LiveResponse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { formatNumber, formatTime } from '@/util/format'
export function LiveResponse(data: LiveRoom): JSX.Element {
let title = ''

title += `👀 ${formatNumber(String(data.liveRoomUserInfo.liveRoom.liveRoomStats.userCount))} `
title += `👀 ${formatNumber(String(data.liveRoomUserInfo.liveRoom.liveRoomStats.userCount))} `

if(data.liveRoomUserInfo.liveRoom.status !== 4) { // live has NOT ended
title += `🔴 LIVE `
if (data.liveRoomUserInfo.liveRoom.status !== 4) {
// live has NOT ended
title += `🕒 ${formatTime(data.liveRoomUserInfo.liveRoom.startTime)} `
} else {
title += `⌛ ENDED `
Expand Down Expand Up @@ -48,7 +48,8 @@ export function LiveResponse(data: LiveRoom): JSX.Element {
},
{
name: 'og:image',
content: data.liveRoomUserInfo.user.avatarLarger
content:
'https://fxtiktok-rewrite.dargy.workers.dev/generate/livePic/' + data.liveRoomUserInfo.user.uniqueId
},
{
name: 'og:image:type',
Expand Down
2 changes: 1 addition & 1 deletion src/templates/pages/VideoResponse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function VideoResponse(data: ItemStruct): JSX.Element {
...videoMeta,
{
name: 'og:image',
content: "https://fxtiktok-rewrite.dargy.workers.dev/generate/image/" + data.id + "?index=" + i
content: 'https://fxtiktok-rewrite.dargy.workers.dev/generate/image/' + data.id + '?index=' + i
},
{
name: 'og:image:type',
Expand Down

0 comments on commit 8e86d8d

Please sign in to comment.