🚸 (videoBubble) Reparse variable video URL to correctly detect provider
This commit is contained in:
@@ -25,6 +25,7 @@ import { injectVariableValuesInPictureChoiceBlock } from './blocks/inputs/pictur
|
||||
import { getPrefilledInputValue } from './getPrefilledValue'
|
||||
import { parseDateInput } from './blocks/inputs/date/parseDateInput'
|
||||
import { deepParseVariables } from './variables/deepParseVariables'
|
||||
import { parseVideoUrl } from '@typebot.io/lib/parseVideoUrl'
|
||||
|
||||
export const executeGroup =
|
||||
(
|
||||
@@ -176,6 +177,13 @@ const parseBubbleBlock =
|
||||
},
|
||||
}
|
||||
}
|
||||
case BubbleBlockType.VIDEO: {
|
||||
const parsedContent = deepParseVariables(variables)(block.content)
|
||||
return {
|
||||
...block,
|
||||
content: parsedContent.url ? parseVideoUrl(parsedContent.url) : {},
|
||||
}
|
||||
}
|
||||
default:
|
||||
return deepParseVariables(variables)(block)
|
||||
}
|
||||
|
||||
20
packages/lib/parseVideoUrl.ts
Normal file
20
packages/lib/parseVideoUrl.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { VideoBubbleContentType } from '@typebot.io/schemas/features/blocks/bubbles/video/enums'
|
||||
|
||||
const vimeoRegex = /vimeo\.com\/(\d+)/
|
||||
const youtubeRegex = /youtube\.com\/(watch\?v=|shorts\/)(\w+)|youtu\.be\/(\w+)/
|
||||
|
||||
export 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 }
|
||||
}
|
||||
Reference in New Issue
Block a user