From a2523f14aea6bb8118a640124b9e6ebfbb1f92c2 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 21 Jan 2023 09:15:18 -0600 Subject: [PATCH] feat: soundcloud embed --- public/index.html | 2 +- src/Const.ts | 8 +++++++- src/Element/SoundCloudEmded.tsx | 16 ++++++++++++++++ src/Element/Text.tsx | 6 +++++- 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/Element/SoundCloudEmded.tsx diff --git a/public/index.html b/public/index.html index 566dc589..69769402 100644 --- a/public/index.html +++ b/public/index.html @@ -8,7 +8,7 @@ + content="default-src 'self'; child-src 'none'; worker-src 'self'; frame-src youtube.com www.youtube.com https://platform.twitter.com https://embed.tidal.com https://w.soundcloud.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src wss://* 'self' https://*; img-src * data:; font-src https://fonts.gstatic.com; media-src *; script-src 'self' https://static.cloudflareinsights.com https://platform.twitter.com https://embed.tidal.com;" /> diff --git a/src/Const.ts b/src/Const.ts index 26103cbb..bcea7a8b 100644 --- a/src/Const.ts +++ b/src/Const.ts @@ -88,4 +88,10 @@ export const HashtagRegex = /(#[^\s!@#$%^&*()=+.\/,\[{\]};:'"?><]+)/; /** * Tidal share link regex */ -export const TidalRegex = /tidal\.com\/(?:browse\/)?(\w+)\/([a-z0-9-]+)/i; \ No newline at end of file +export const TidalRegex = /tidal\.com\/(?:browse\/)?(\w+)\/([a-z0-9-]+)/i; + +/** + * SoundCloud regex + */ + +export const SoundCloudRegex = /soundcloud\.com\/(?!live)([a-zA-Z0-9]+)\/([a-zA-Z0-9-]+)/ diff --git a/src/Element/SoundCloudEmded.tsx b/src/Element/SoundCloudEmded.tsx new file mode 100644 index 00000000..89328963 --- /dev/null +++ b/src/Element/SoundCloudEmded.tsx @@ -0,0 +1,16 @@ +const SoundCloudEmbed = ({link}: {link: string}) => { + + return( + <> + + + ) +} + +export default SoundCloudEmbed; diff --git a/src/Element/Text.tsx b/src/Element/Text.tsx index b1d26b14..e74a5cef 100644 --- a/src/Element/Text.tsx +++ b/src/Element/Text.tsx @@ -4,7 +4,7 @@ import { Link } from "react-router-dom"; import ReactMarkdown from "react-markdown"; import { TwitterTweetEmbed } from "react-twitter-embed"; -import { UrlRegex, FileExtensionRegex, MentionRegex, InvoiceRegex, YoutubeUrlRegex, TweetUrlRegex, HashtagRegex, TidalRegex } from "Const"; +import { UrlRegex, FileExtensionRegex, MentionRegex, InvoiceRegex, YoutubeUrlRegex, TweetUrlRegex, HashtagRegex, TidalRegex, SoundCloudRegex } from "Const"; import { eventLink, hexToBech32 } from "Util"; import Invoice from "Element/Invoice"; import Hashtag from "Element/Hashtag"; @@ -16,6 +16,7 @@ import TidalEmbed from "Element/TidalEmbed"; import { useSelector } from 'react-redux'; import { RootState } from 'State/Store'; import { UserPreferences } from 'State/Login'; +import SoundCloudEmbed from 'Element/SoundCloudEmded' function transformHttpLink(a: string, pref: UserPreferences) { try { @@ -26,6 +27,7 @@ function transformHttpLink(a: string, pref: UserPreferences) { const youtubeId = YoutubeUrlRegex.test(a) && RegExp.$1; const tweetId = TweetUrlRegex.test(a) && RegExp.$2; const tidalId = TidalRegex.test(a) && RegExp.$1; + const soundcloundId = SoundCloudRegex.test(a) && RegExp.$1; const extension = FileExtensionRegex.test(url.pathname.toLowerCase()) && RegExp.$1; if (extension) { switch (extension) { @@ -71,6 +73,8 @@ function transformHttpLink(a: string, pref: UserPreferences) { ) } else if (tidalId) { return + } else if (soundcloundId){ + return } else { return e.stopPropagation()} target="_blank" rel="noreferrer" className="ext">{a} }