Skip to content

Commit

Permalink
minor: switch to an index generate system for images
Browse files Browse the repository at this point in the history
to prevent tiktok expiry
  • Loading branch information
okdargy committed Jun 24, 2024
1 parent 5acec12 commit 15e2e5b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,17 @@ app.get('/generate/video/:videoId', async (c) => {

app.get('/generate/image/:videoId', async (c) => {
const { videoId } = c.req.param()
const index = c.req.query('index') || 0

if (!videoId) return new Response('Missing video ID', { status: 400 })
if (!awemeIdPattern.test(videoId)) return new Response('Invalid video ID', { status: 400 })
if (isNaN(Number(index))) return new Response('Invalid image index', { status: 400 })

try {
const data = await scrapeVideoData(videoId)

if ('imagePost' in data && data.imagePost.images.length > 0) {
return c.redirect(data.imagePost.images[0].imageURL.urlList[0]);
if ('imagePost' in data && data.imagePost.images.length > 0 && +index < data.imagePost.images.length) {
return c.redirect(data.imagePost.images[+index].imageURL.urlList[0]);
} else {
throw new Error('Image not found');
}
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: data.imagePost.images[i].imageURL.urlList[0]
content: "https://fxtiktok-rewrite.dargy.workers.dev/generate/image/" + data.id + "?index=" + i
},
{
name: 'og:image:type',
Expand Down

0 comments on commit 15e2e5b

Please sign in to comment.