diff --git a/package.json b/package.json
index a720f226..c0fb80d2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "photon-lemmy",
- "version": "1.24.0",
+ "version": "1.24.1",
"private": true,
"scripts": {
"dev": "vite dev",
diff --git a/src/lib/components/lemmy/post/helpers.ts b/src/lib/components/lemmy/post/helpers.ts
index 2f680ad1..543e294a 100644
--- a/src/lib/components/lemmy/post/helpers.ts
+++ b/src/lib/components/lemmy/post/helpers.ts
@@ -27,26 +27,31 @@ export const bestImageURL = (
return post.url ?? ''
}
-const YOUTUBE_REGEX = /^(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(\w|-){11}$/
+const YOUTUBE_REGEX = /^(?:(?:https?:)?\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/
-export const isYoutubeLink = (url?: string): boolean => {
- if (!url) return false
+export const isYoutubeLink = (url?: string): RegExpMatchArray | null => {
+ if (!url) return null
- return YOUTUBE_REGEX.test(url)
+ return url.match(url)
}
export const postLink = (post: Post) => `/post/${getInstance()}/${post.id}`
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
-export type IframeType = 'youtube' | 'none'
+export type IframeType = 'youtube' | 'video' | 'none'
export const mediaType = (post: Post, view: View = 'cozy'): MediaType => {
if (post.url) {
if (isImage(post.url)) return 'image'
- if (isVideo(post.url)) return 'video'
+ if (isVideo(post.url)) return 'iframe'
if (isYoutubeLink(post.url)) return 'iframe'
return 'embed'
}
+ return 'none'
+}
+export const iframeType = (post: Post): IframeType => {
+ if (isVideo(post.url)) return 'video'
+ if (isYoutubeLink(post.url)) return 'youtube'
return 'none'
}
\ No newline at end of file
diff --git a/src/lib/components/lemmy/post/media/PostIframe.svelte b/src/lib/components/lemmy/post/media/PostIframe.svelte
index 08c22ba3..76ac03ac 100644
--- a/src/lib/components/lemmy/post/media/PostIframe.svelte
+++ b/src/lib/components/lemmy/post/media/PostIframe.svelte
@@ -30,6 +30,10 @@
export let opened = !$userSettings.embeds.clickToView
const urlToEmbed = (inputUrl: string) => {
+ if (type == 'video') {
+ return inputUrl
+ }
+
if (type == 'youtube') {
const url = new URL(inputUrl)
const videoID = url.searchParams.get('v')
@@ -56,6 +60,12 @@
text: 'YouTube Video',
}
}
+ case 'video': {
+ return {
+ icon: VideoCamera,
+ text: 'Video',
+ }
+ }
default: {
return {
icon: PuzzlePiece,
@@ -70,18 +80,25 @@
{#if opened}
-
+ {#if type == 'video'}
+
+
+ {:else}
+
+ {/if}
{:else}