fix(notes): render video preview
This commit is contained in:
parent
5f33c5e68a
commit
83adfe3964
@ -7,7 +7,7 @@ import { BlogPreview } from './internal/BlogPreview'
|
|||||||
import { ModPreview } from './internal/ModPreview'
|
import { ModPreview } from './internal/ModPreview'
|
||||||
import { NoteWrapper } from './internal/NoteWrapper'
|
import { NoteWrapper } from './internal/NoteWrapper'
|
||||||
import { NIP05_REGEX } from 'nostr-tools/nip05'
|
import { NIP05_REGEX } from 'nostr-tools/nip05'
|
||||||
import { isValidImageUrl, isValidUrl } from 'utils'
|
import { isValidImageUrl, isValidUrl, isValidVideoUrl } from 'utils'
|
||||||
|
|
||||||
interface NoteRenderProps {
|
interface NoteRenderProps {
|
||||||
content: string
|
content: string
|
||||||
@ -36,9 +36,12 @@ export const NoteRender = ({ content }: NoteRenderProps) => {
|
|||||||
const [href] = part.match(link) || []
|
const [href] = part.match(link) || []
|
||||||
|
|
||||||
if (href && isValidUrl(href)) {
|
if (href && isValidUrl(href)) {
|
||||||
// Image
|
|
||||||
if (isValidImageUrl(href)) {
|
if (isValidImageUrl(href)) {
|
||||||
|
// Image
|
||||||
return <img className='imgFeedRender' src={href} alt='' />
|
return <img className='imgFeedRender' src={href} alt='' />
|
||||||
|
} else if (isValidVideoUrl(href)) {
|
||||||
|
// Video
|
||||||
|
return <video className='videoFeedRender' src={href} controls />
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +60,11 @@ export const isValidImageUrl = (url: string) => {
|
|||||||
return regex.test(url)
|
return regex.test(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const isValidVideoUrl = (url: string) => {
|
||||||
|
const regex = /\.(mp4|mkv|webm|mov)$/
|
||||||
|
return regex.test(url)
|
||||||
|
}
|
||||||
|
|
||||||
export const isReachable = async (url: string) => {
|
export const isReachable = async (url: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url, { method: 'HEAD' })
|
const response = await fetch(url, { method: 'HEAD' })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user