forked from Kieran/snort
commit
50b9694419
@ -8,7 +8,7 @@
|
|||||||
<meta name="theme-color" content="#000000" />
|
<meta name="theme-color" content="#000000" />
|
||||||
<meta name="description" content="Fast nostr web ui" />
|
<meta name="description" content="Fast nostr web ui" />
|
||||||
<meta http-equiv="Content-Security-Policy"
|
<meta http-equiv="Content-Security-Policy"
|
||||||
content="default-src 'self'; child-src 'none'; worker-src 'self'; frame-src youtube.com www.youtube.com https://platform.twitter.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;" />
|
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; 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;" />
|
||||||
|
|
||||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/nostrich_512.png" />
|
<link rel="apple-touch-icon" href="%PUBLIC_URL%/nostrich_512.png" />
|
||||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||||
|
@ -84,3 +84,8 @@ export const TweetUrlRegex = /https?:\/\/twitter\.com\/(?:#!\/)?(\w+)\/status(?:
|
|||||||
* Hashtag regex
|
* Hashtag regex
|
||||||
*/
|
*/
|
||||||
export const HashtagRegex = /(#[^\s!@#$%^&*()=+.\/,\[{\]};:'"?><]+)/;
|
export const HashtagRegex = /(#[^\s!@#$%^&*()=+.\/,\[{\]};:'"?><]+)/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tidal share link regex
|
||||||
|
*/
|
||||||
|
export const TidalRegex = /tidal\.com\/browse\/(\w+)\/([a-z0-9-]+)/i;
|
@ -4,7 +4,7 @@ import { Link } from "react-router-dom";
|
|||||||
import ReactMarkdown from "react-markdown";
|
import ReactMarkdown from "react-markdown";
|
||||||
import { TwitterTweetEmbed } from "react-twitter-embed";
|
import { TwitterTweetEmbed } from "react-twitter-embed";
|
||||||
|
|
||||||
import { UrlRegex, FileExtensionRegex, MentionRegex, InvoiceRegex, YoutubeUrlRegex, TweetUrlRegex, HashtagRegex } from "Const";
|
import { UrlRegex, FileExtensionRegex, MentionRegex, InvoiceRegex, YoutubeUrlRegex, TweetUrlRegex, HashtagRegex, TidalRegex } from "Const";
|
||||||
import { eventLink, hexToBech32 } from "Util";
|
import { eventLink, hexToBech32 } from "Util";
|
||||||
import Invoice from "Element/Invoice";
|
import Invoice from "Element/Invoice";
|
||||||
import Hashtag from "Element/Hashtag";
|
import Hashtag from "Element/Hashtag";
|
||||||
@ -12,12 +12,14 @@ import Hashtag from "Element/Hashtag";
|
|||||||
import Tag from "Nostr/Tag";
|
import Tag from "Nostr/Tag";
|
||||||
import { MetadataCache } from "Db/User";
|
import { MetadataCache } from "Db/User";
|
||||||
import Mention from "Element/Mention";
|
import Mention from "Element/Mention";
|
||||||
|
import TidalEmbed from "Element/TidalEmbed";
|
||||||
|
|
||||||
function transformHttpLink(a: string) {
|
function transformHttpLink(a: string) {
|
||||||
try {
|
try {
|
||||||
const url = new URL(a);
|
const url = new URL(a);
|
||||||
const youtubeId = YoutubeUrlRegex.test(a) && RegExp.$1;
|
const youtubeId = YoutubeUrlRegex.test(a) && RegExp.$1;
|
||||||
const tweetId = TweetUrlRegex.test(a) && RegExp.$2;
|
const tweetId = TweetUrlRegex.test(a) && RegExp.$2;
|
||||||
|
const tidalId = TidalRegex.test(a) && RegExp.$1;
|
||||||
const extension = FileExtensionRegex.test(url.pathname.toLowerCase()) && RegExp.$1;
|
const extension = FileExtensionRegex.test(url.pathname.toLowerCase()) && RegExp.$1;
|
||||||
if (extension) {
|
if (extension) {
|
||||||
switch (extension) {
|
switch (extension) {
|
||||||
@ -61,6 +63,8 @@ function transformHttpLink(a: string) {
|
|||||||
<br />
|
<br />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
} else if (tidalId) {
|
||||||
|
return <TidalEmbed link={a} />
|
||||||
} else {
|
} else {
|
||||||
return <a href={a} onClick={(e) => e.stopPropagation()} target="_blank" rel="noreferrer" className="ext">{a}</a>
|
return <a href={a} onClick={(e) => e.stopPropagation()} target="_blank" rel="noreferrer" className="ext">{a}</a>
|
||||||
}
|
}
|
||||||
|
27
src/Element/TidalEmbed.tsx
Normal file
27
src/Element/TidalEmbed.tsx
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { useEffect, useMemo } from "react";
|
||||||
|
import { TidalRegex } from "Const";
|
||||||
|
|
||||||
|
const TidalEmbed = ({ link }: { link: string }) => {
|
||||||
|
const data = useMemo(() => {
|
||||||
|
const match = link.match(TidalRegex);
|
||||||
|
if (match?.length != 3) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
let type = match[1][0];
|
||||||
|
let id = match[2];
|
||||||
|
return { type, id };
|
||||||
|
}, [link]);
|
||||||
|
|
||||||
|
const ScriptSrc = "https://embed.tidal.com/tidal-embed.js";
|
||||||
|
useEffect(() => {
|
||||||
|
let sTag = document.createElement("script");
|
||||||
|
sTag.src = ScriptSrc;
|
||||||
|
sTag.async = true;
|
||||||
|
document.head.appendChild(sTag);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!data) return <a href={link} target="_blank" rel="noreferrer" onClick={(e) => e.stopPropagation()} className="ext">{link}</a>;
|
||||||
|
return <div className="tidal-embed" data-type={data.type} data-id={data.id}></div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TidalEmbed;
|
Loading…
Reference in New Issue
Block a user