2
0

🚸 (videoBubble) Reparse variable video URL to correctly detect provider

This commit is contained in:
Baptiste Arnaud
2023-10-03 11:44:51 +02:00
parent a53d128fb0
commit a7b784b446
4 changed files with 55 additions and 35 deletions

View File

@@ -1,5 +1,5 @@
import { useScopedI18n } from '@/locales'
import { Box, Text } from '@chakra-ui/react'
import { Box, Text, Image } from '@chakra-ui/react'
import { VideoBubbleBlock, VideoBubbleContentType } from '@typebot.io/schemas'
type Props = {
@@ -10,24 +10,34 @@ export const VideoBubbleContent = ({ block }: Props) => {
const scopedT = useScopedI18n('editor.blocks.bubbles.video.node')
if (!block.content?.url || !block.content.type)
return <Text color="gray.500">{scopedT('clickToEdit.text')}</Text>
const containsVariables =
block.content?.url?.includes('{{') && block.content.url.includes('}}')
switch (block.content.type) {
case VideoBubbleContentType.URL:
return (
<Box w="full" h="120px" pos="relative">
<video
key={block.content.url}
controls
style={{
width: '100%',
height: '100%',
position: 'absolute',
left: '0',
top: '0',
borderRadius: '10px',
}}
>
<source src={block.content.url} />
</video>
{containsVariables ? (
<Image
src="/images/dynamic-image.png"
alt="Dynamic video thumbnail"
rounded="md"
/>
) : (
<video
key={block.content.url}
controls
style={{
width: '100%',
height: '100%',
position: 'absolute',
left: '0',
top: '0',
borderRadius: '10px',
}}
>
<source src={block.content.url} />
</video>
)}
</Box>
)
case VideoBubbleContentType.VIMEO:

View File

@@ -1,10 +1,8 @@
import { Stack, Text } from '@chakra-ui/react'
import { VideoBubbleContent, VideoBubbleContentType } from '@typebot.io/schemas'
import { VideoBubbleContent } from '@typebot.io/schemas'
import { TextInput } from '@/components/inputs'
import { useScopedI18n } from '@/locales'
const vimeoRegex = /vimeo\.com\/(\d+)/
const youtubeRegex = /youtube\.com\/(watch\?v=|shorts\/)(\w+)|youtu\.be\/(\w+)/
import { parseVideoUrl } from '@typebot.io/lib/parseVideoUrl'
type Props = {
content?: VideoBubbleContent
@@ -34,19 +32,3 @@ export const VideoUploadContent = ({ content, onSubmit }: Props) => {
</Stack>
)
}
const parseVideoUrl = (
url: string
): { type: VideoBubbleContentType; url: string; id?: string } => {
if (vimeoRegex.test(url)) {
const id = url.match(vimeoRegex)?.at(1)
if (!id) return { type: VideoBubbleContentType.URL, url }
return { type: VideoBubbleContentType.VIMEO, url, id }
}
if (youtubeRegex.test(url)) {
const id = url.match(youtubeRegex)?.at(2) ?? url.match(youtubeRegex)?.at(3)
if (!id) return { type: VideoBubbleContentType.URL, url }
return { type: VideoBubbleContentType.YOUTUBE, url, id }
}
return { type: VideoBubbleContentType.URL, url }
}