From 4bb6f67e52747248791dc32fdad8e09dd9bb4975 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Thu, 3 Aug 2023 11:26:16 -0700 Subject: [PATCH] feat: add basic video support --- src/lib/ui/image.ts | 8 +++++--- src/routes/post/[instance]/[id]/+page.svelte | 12 ++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib/ui/image.ts b/src/lib/ui/image.ts index 0393f74d..12d10407 100644 --- a/src/lib/ui/image.ts +++ b/src/lib/ui/image.ts @@ -4,8 +4,10 @@ export const isImage = (url: string | undefined) => { return /\.(jpeg|jpg|gif|png|svg|bmp|webp)$/i.test(new URL(url).pathname) } -export const isVideo = (url: string | undefined) => { - if (!url) return false +export const isVideo = (inputUrl: string | undefined) => { + if (!inputUrl) return false - return new URL(url).pathname.toLowerCase().endsWith('.mp4') + const url = new URL(inputUrl).pathname.toLowerCase() + + return url.endsWith('mp4') || url.endsWith('webm') || url.endsWith('mov') } diff --git a/src/routes/post/[instance]/[id]/+page.svelte b/src/routes/post/[instance]/[id]/+page.svelte index 85bf9440..e5d6bfac 100644 --- a/src/routes/post/[instance]/[id]/+page.svelte +++ b/src/routes/post/[instance]/[id]/+page.svelte @@ -4,7 +4,7 @@ buildCommentsTreeAsync, } from '$lib/components/lemmy/comment/comments.js' import Comments from '$lib/components/lemmy/comment/Comments.svelte' - import { isImage } from '$lib/ui/image.js' + import { isImage, isVideo } from '$lib/ui/image.js' import { getClient } from '$lib/lemmy.js' import CommentForm from '$lib/components/lemmy/comment/CommentForm.svelte' import { onMount } from 'svelte' @@ -108,6 +108,11 @@ alt={post.name} class="rounded-md max-w-screen max-h-[80vh] mx-auto" /> + {:else if isVideo(post.url)} + + {:else if post.url && !post.thumbnail_url} - {:else if post.embed_video_url} - - {/if} {#if post.body}