From 8e86d8d7e7aab12a147cd06ddccba4dfa00f0956 Mon Sep 17 00:00:00 2001 From: dargy Date: Mon, 29 Jul 2024 00:11:53 -0500 Subject: [PATCH] fix: expiring profile pictures on live endpoints --- README.md | 26 +++++++++++----------- src/index.ts | 31 ++++++++++++++++++++++++--- src/templates/pages/LiveResponse.tsx | 9 ++++---- src/templates/pages/VideoResponse.tsx | 2 +- 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 139f3a0..5a0603f 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ Embed TikTok videos and slideshows on Discord with just `s/i/n` | Slideshow embeds | | Live Preview | -| :--------------------------------------------------------------------------------------------------------------------------: | -| Live video embeds | +| :----------------------------------------------------------------------------------------------------------------: | +| Live video embeds | | Direct Preview | | :--------------------------------------------------------------------------------------------------------------------: | @@ -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 diff --git a/src/index.ts b/src/index.ts index 53ce499..0203e67 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) { @@ -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, { @@ -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', diff --git a/src/templates/pages/LiveResponse.tsx b/src/templates/pages/LiveResponse.tsx index 5fb566a..60471d4 100644 --- a/src/templates/pages/LiveResponse.tsx +++ b/src/templates/pages/LiveResponse.tsx @@ -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 ` @@ -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', diff --git a/src/templates/pages/VideoResponse.tsx b/src/templates/pages/VideoResponse.tsx index 86000ea..1772287 100644 --- a/src/templates/pages/VideoResponse.tsx +++ b/src/templates/pages/VideoResponse.tsx @@ -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',