refac
This commit is contained in:
@@ -1,10 +1,37 @@
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import { embed, showControls, showEmbeds } from '$lib/stores';
|
||||
|
||||
import FullHeightIframe from '$lib/components/common/FullHeightIframe.svelte';
|
||||
import XMark from '$lib/components/icons/XMark.svelte';
|
||||
|
||||
export let overlay = false;
|
||||
|
||||
const getSrcUrl = (url: string, chatId?: string, messageId?: string) => {
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
|
||||
if (chatId) {
|
||||
parsed.searchParams.set('chat_id', chatId);
|
||||
}
|
||||
|
||||
if (messageId) {
|
||||
parsed.searchParams.set('message_id', messageId);
|
||||
}
|
||||
|
||||
return parsed.toString();
|
||||
} catch {
|
||||
// Fallback for relative URLs or invalid input
|
||||
const hasQuery = url.includes('?');
|
||||
const parts = [];
|
||||
|
||||
if (chatId) parts.push(`chat_id=${encodeURIComponent(chatId)}`);
|
||||
if (messageId) parts.push(`message_id=${encodeURIComponent(messageId)}`);
|
||||
|
||||
if (parts.length === 0) return url;
|
||||
|
||||
return url + (hasQuery ? '&' : '?') + parts.join('&');
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
{#if $embed}
|
||||
@@ -40,7 +67,11 @@
|
||||
<div class=" absolute top-0 left-0 right-0 bottom-0 z-10"></div>
|
||||
{/if}
|
||||
|
||||
<FullHeightIframe src={$embed?.url} iframeClassName="w-full h-full" />
|
||||
<FullHeightIframe
|
||||
src={getSrcUrl($embed?.url ?? '', $embed?.chatId, $embed?.messageId)}
|
||||
payload={$embed?.source ?? null}
|
||||
iframeClassName="w-full h-full"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user