From 2731f74fd7d9b90a7d2813d62c0ba071bf83e12c Mon Sep 17 00:00:00 2001 From: gsovereignty Date: Mon, 29 Apr 2024 23:53:50 +1000 Subject: [PATCH] problem: can't view videos --- src/lib/components/RenderNoteContent.svelte | 40 ++++++++++-- src/lib/views/messages/Kind1.svelte | 69 --------------------- 2 files changed, 35 insertions(+), 74 deletions(-) delete mode 100644 src/lib/views/messages/Kind1.svelte diff --git a/src/lib/components/RenderNoteContent.svelte b/src/lib/components/RenderNoteContent.svelte index 375263d..f9135ef 100644 --- a/src/lib/components/RenderNoteContent.svelte +++ b/src/lib/components/RenderNoteContent.svelte @@ -2,22 +2,39 @@ import DOMPurify from 'dompurify'; export let inputString = ''; + function extractYouTubeVideoID(url: string) { + const regex = + /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/; + const match = url.match(regex); + if (match && match[1]) { + return match[1]; + } + return undefined; + } + // Format the input string: replaces line breaks with
tags and image URLs with tags function formatInput(input: string) { //ethically cleanse the input input = DOMPurify.sanitize(input); // replace newline characters with
tags - let formattedInput = input.replace(/(\r\n|\n|\r)/gm, '
'); + let formattedInput = input.replace(/(\r\n|\n|\r)/gm, '
'); const nostr = /nostr:\S+/g; - formattedInput = formattedInput.replace(nostr, (s)=>{ - s = s.replace("nostr:", ""); - return ` njump ` //todo: render mentioned notes inline, render usernames for npubs, + formattedInput = formattedInput.replace(nostr, (s) => { + s = s.replace('nostr:', ''); + return ` njump `; //todo: render mentioned notes inline, render usernames for npubs, + }); + + // regex to find video URLs + const vurlRegex = /https?:\/\/\S+\.(mp4)\b/g; + + formattedInput = formattedInput.replace(vurlRegex, (url) => { + return `