fix: show videos in iframes, close #222

This commit is contained in:
Xylight committed 2023-12-12 16:08:46 -08:00
1 parent d75fcb328f
commit 0557b520ef
4 files changed
+40 -17

No files matched your search

+11 -6
View File
@@ -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'
}