Skip to content

Commit

Permalink
feat: support twitch oembed (#4336)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Dec 24, 2023
1 parent 16e6fd1 commit 28b31af
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions apps/api/src/utils/oembed/meta/generateIframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const knownSites = [
'youtube.com',
'youtu.be',
'tape.xyz',
'twitch.tv',
'open.spotify.com',
'soundcloud.com',
'oohlala.xyz'
Expand All @@ -21,6 +22,7 @@ const youtubeRegex =
/^https?:\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w-]+)(?:\?.*)?$/;
const tapeRegex =
/^https?:\/\/tape\.xyz\/watch\/[\dA-Za-z-]+(\?si=[\dA-Za-z]+)?$/;
const twitchRegex = /^https?:\/\/www\.twitch\.tv\/videos\/[\dA-Za-z-]+$/;

const generateIframe = (
embedUrl: null | string,
Expand Down Expand Up @@ -51,6 +53,17 @@ const generateIframe = (

return null;
}
case 'twitch.tv': {
const twitchEmbedUrl = pickedUrl.replace(
'&player=facebook&autoplay=true&parent=meta.tag',
'&player=hey&autoplay=false&parent=hey.xyz'
);
if (twitchRegex.test(url)) {
return `<iframe src="${twitchEmbedUrl}" ${universalSize} allowfullscreen></iframe>`;
}

return null;
}
case 'open.spotify.com': {
const spotifySize = `style="max-width: 100%;" width="100%"`;
if (spotifyTrackUrlRegex.test(url)) {
Expand Down

0 comments on commit 28b31af

Please sign in to comment.