diff --git a/src/lib/components/chat/MessageInput/AttachWebpageModal.svelte b/src/lib/components/chat/MessageInput/AttachWebpageModal.svelte index e3ea186d05..ae6f63ef22 100644 --- a/src/lib/components/chat/MessageInput/AttachWebpageModal.svelte +++ b/src/lib/components/chat/MessageInput/AttachWebpageModal.svelte @@ -7,7 +7,7 @@ import Modal from '$lib/components/common/Modal.svelte'; import XMark from '$lib/components/icons/XMark.svelte'; - import { isValidHttpUrl } from '$lib/utils'; + import { isValidHttpUrl, isYoutubeUrl } from '$lib/utils'; export let show = false; export let onSubmit: (e) => void; @@ -17,10 +17,7 @@ const submitHandler = () => { if (isValidHttpUrl(url)) { onSubmit({ - type: - url.startsWith('https://www.youtube.com') || url.startsWith('https://youtu.be') || url.startsWith('https://youtube.com') || url.startsWith('https://m.youtube.com') - ? 'youtube' - : 'web', + type: isYoutubeUrl(url) ? 'youtube' : 'web', data: url }); diff --git a/src/lib/components/chat/MessageInput/Commands/Knowledge.svelte b/src/lib/components/chat/MessageInput/Commands/Knowledge.svelte index 5a6ce96cc4..077f97d416 100644 --- a/src/lib/components/chat/MessageInput/Commands/Knowledge.svelte +++ b/src/lib/components/chat/MessageInput/Commands/Knowledge.svelte @@ -7,7 +7,7 @@ dayjs.extend(relativeTime); import { tick, getContext, onMount, onDestroy } from 'svelte'; - import { removeLastWordFromString, isValidHttpUrl } from '$lib/utils'; + import { removeLastWordFromString, isValidHttpUrl, isYoutubeUrl } from '$lib/utils'; import Tooltip from '$lib/components/common/Tooltip.svelte'; import DocumentPage from '$lib/components/icons/DocumentPage.svelte'; import Database from '$lib/components/icons/Database.svelte'; @@ -36,7 +36,7 @@ : items), ...(query.startsWith('http') - ? query.startsWith('https://www.youtube.com') || query.startsWith('https://youtu.be') + ? isYoutubeUrl(query) ? [{ type: 'youtube', name: query, description: query }] : [ { @@ -228,7 +228,7 @@ {/if} {/each} - {#if query.startsWith('https://www.youtube.com') || query.startsWith('https://youtu.be')} + {#if isYoutubeUrl(query)}