From a3be3d0131acb0ba9740f5e619c6fb3c9116ef83 Mon Sep 17 00:00:00 2001
From: Michael Rhee <77257032+blastshielddown@users.noreply.github.com>
Date: Thu, 9 Mar 2023 11:57:28 -0600
Subject: [PATCH] Add Wavlake embed (#416)
* Add Wavlake embed
* Prettify edits
---
packages/app/public/index.html | 2 +-
packages/app/src/Const.ts | 5 +++++
packages/app/src/Element/HyperText.tsx | 5 +++++
packages/app/src/Element/WavlakeEmbed.tsx | 16 ++++++++++++++++
4 files changed, 27 insertions(+), 1 deletion(-)
create mode 100644 packages/app/src/Element/WavlakeEmbed.tsx
diff --git a/packages/app/public/index.html b/packages/app/public/index.html
index 931a2590..0407d7dc 100644
--- a/packages/app/public/index.html
+++ b/packages/app/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 https://www.mixcloud.com https://open.spotify.com https://player.twitch.tv https://embed.music.apple.com https://nostrnests.com https://player.wavlake.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src *; img-src * data:; font-src https://fonts.gstatic.com; media-src *; script-src 'self' 'wasm-unsafe-eval' https://static.cloudflareinsights.com https://platform.twitter.com https://embed.tidal.com;" />
diff --git a/packages/app/src/Const.ts b/packages/app/src/Const.ts
index 634fa2be..738f8fbd 100644
--- a/packages/app/src/Const.ts
+++ b/packages/app/src/Const.ts
@@ -165,3 +165,8 @@ export const NostrNestsRegex = /nostrnests\.com\/[a-zA-Z0-9]+/i;
* Magnet link parser
*/
export const MagnetRegex = /(magnet:[\S]+)/i;
+
+/**
+ * Wavlake embed regex
+ */
+export const WavlakeRegex = /player\.wavlake\.com\/(track)\/([.a-zA-Z0-9-]+)/;
diff --git a/packages/app/src/Element/HyperText.tsx b/packages/app/src/Element/HyperText.tsx
index d31d2827..165fdaa2 100644
--- a/packages/app/src/Element/HyperText.tsx
+++ b/packages/app/src/Element/HyperText.tsx
@@ -15,6 +15,7 @@ import {
TwitchRegex,
AppleMusicRegex,
NostrNestsRegex,
+ WavlakeRegex,
} from "Const";
import { RootState } from "State/Store";
import SoundCloudEmbed from "Element/SoundCloudEmded";
@@ -25,6 +26,7 @@ import { ProxyImg } from "Element/ProxyImg";
import TwitchEmbed from "Element/TwitchEmbed";
import AppleMusicEmbed from "Element/AppleMusicEmbed";
import NostrNestsEmbed from "Element/NostrNestsEmbed";
+import WavlakeEmbed from "Element/WavlakeEmbed";
export default function HyperText({ link, creator }: { link: string; creator: HexKey }) {
const pref = useSelector((s: RootState) => s.login.preferences);
@@ -70,6 +72,7 @@ export default function HyperText({ link, creator }: { link: string; creator: He
const isTwitchLink = TwitchRegex.test(a);
const isAppleMusicLink = AppleMusicRegex.test(a);
const isNostrNestsLink = NostrNestsRegex.test(a);
+ const isWavlakeLink = WavlakeRegex.test(a);
const extension = FileExtensionRegex.test(url.pathname.toLowerCase()) && RegExp.$1;
if (extension && !isAppleMusicLink) {
switch (extension) {
@@ -144,6 +147,8 @@ export default function HyperText({ link, creator }: { link: string; creator: He
,
,
];
+ } else if (isWavlakeLink) {
+ return ;
} else {
return (
e.stopPropagation()} target="_blank" rel="noreferrer" className="ext">
diff --git a/packages/app/src/Element/WavlakeEmbed.tsx b/packages/app/src/Element/WavlakeEmbed.tsx
new file mode 100644
index 00000000..aa3371ad
--- /dev/null
+++ b/packages/app/src/Element/WavlakeEmbed.tsx
@@ -0,0 +1,16 @@
+const WavlakeEmbed = ({ link }: { link: string }) => {
+ const convertedUrl = link.replace(/\/(track)\/([a-zA-Z0-9]+)/, "/embed/$1/$2");
+
+ return (
+
+ );
+};
+
+export default WavlakeEmbed;