Skip to content

fix tiktok bot media urls#91

Closed
rosethornbush wants to merge 1 commit into
mainfrom
fix/tiktok-video-urls
Closed

fix tiktok bot media urls#91
rosethornbush wants to merge 1 commit into
mainfrom
fix/tiktok-video-urls

Conversation

@rosethornbush

Copy link
Copy Markdown
Contributor

Summary

  • return all TikTok video URL candidates from the platform transform without worker-side probing
  • resolve TikTok video candidates in the bot builder with a one-byte range request and Discordbot UA
  • send Discord the final redirected video URL only when TikTok returns video content

Root cause

The API worker can be blocked by TikTok when checking media URLs, but the bot can resolve the playable TikTok URL immediately before sending the Discord message. Returning all candidates keeps the API response complete while letting the bot choose the URL Discord can actually use.

Validation

  • pnpm exec moon ci bot:lint bot:fmt/check platforms:lint platforms:fmt/check
  • repro URL returned four TikTok candidates
  • bot-side check dropped the 403 candidates and kept the aweme/v1/play candidate returning 206 video/mp4

Fixes #86

@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b268d04

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
embedly-docs b268d04 Commit Preview URL

Branch Preview URL
Jun 23 2026, 03:23 AM

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 2 comments

continue;
}

const response = await fetch(item.url, {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[🟠 High] [🔵 Bug]

resolveMedia performs a network fetch for each TikTok candidate inside buildEmbed but does not catch fetch/cancel exceptions, so transient network failures (DNS/TLS/socket reset) throw out of embed construction and fail the request instead of degrading gracefully. This turns a best-effort media URL refinement step into a hard failure path; wrap the probe in try/catch and continue with the original item (or skip it) on error.

// apps/bot/src/lib/builder.ts
const response = await fetch(item.url, {
  method: "GET",
  redirect: "follow",
  headers: {

raw.video.downloadAddr,
...(raw.video.PlayAddrStruct?.UrlList ?? []),
].filter((url) => typeof url === "string" && url.length > 0);
return [...new Set(urls)].map((url) => ({ url, type: "video" }));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[🟡 Medium] [🔵 Bug]

The transform now maps every candidate video URL into a distinct media item, but downstream rendering treats NormalizedPost.media as gallery items, not fallback URLs for a single asset. When multiple candidates return playable video, one TikTok post can render duplicate/alternate copies instead of a single resolved video URL; keep candidates as fallback metadata and collapse to one selected URL before emitting gallery media.

// packages/platforms/src/platforms/tiktok.ts
const urls = [
  raw.video.playAddr,
  raw.video.downloadAddr,
  ...(raw.video.PlayAddrStruct?.UrlList ?? []),
];
return [...new Set(urls)].map((url) => ({ url, type: "video" }));

@rosethornbush
rosethornbush marked this pull request as draft June 29, 2026 02:36
@rosethornbush

Copy link
Copy Markdown
Contributor Author

so tiktok seems to be working without this and unless i need it, its kinda pointless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(platforms): tiktok videos fail to load

1 participant