diff --git a/src/components/AddContentModal/utils/__tests__/index.ts b/src/components/AddContentModal/utils/__tests__/index.ts index 1f96daa304..a25c733752 100644 --- a/src/components/AddContentModal/utils/__tests__/index.ts +++ b/src/components/AddContentModal/utils/__tests__/index.ts @@ -6,6 +6,10 @@ describe('youtubeRegex', () => { expect(getInputType('https://www.youtube.com/watch?v=83eQ9flwVS0&ab_channel=EthanChlebowski')).toBe(LINK) }) + it('should assert we can check for youtube live clip regex', async () => { + expect(getInputType('https://youtube.com/live/tkdMgjEFNWs')).toBe(LINK) + }) + it('should assert we can check for twitter spaces regex', async () => { expect(getInputType('https://twitter.com/i/spaces/1zqKVqwrVzlxB?s=20')).toBe(LINK) }) @@ -29,6 +33,9 @@ describe('youtubeRegex', () => { it('should assert we can check for twitter handle regex', async () => { expect(getInputType('https://twitter.com/@KevKevPal')).toBe(TWITTER_HANDLE) }) + it('should assert we can check for youtube live clip regex', async () => { + expect(getInputType('https://www.youtube.com/@MrBeast')).toBe(YOUTUBE_CHANNEL) + }) }) describe('extractNameFromLink', () => { diff --git a/src/components/AddContentModal/utils/index.ts b/src/components/AddContentModal/utils/index.ts index 255b27346d..c960f4174c 100644 --- a/src/components/AddContentModal/utils/index.ts +++ b/src/components/AddContentModal/utils/index.ts @@ -3,6 +3,7 @@ import { DOCUMENT, LINK, TWITTER_HANDLE, TWITTER_SOURCE, WEB_PAGE, YOUTUBE_CHANN export const twitterHandlePattern = /\btwitter\.com\/(?:@)?([\w_]+)(?:$|\?[^/]*$)/ const youtubeRegex = /(https?:\/\/)?(www\.)?youtube\.com\/watch\?v=([A-Za-z0-9_-]+)/ +const youtubeLiveRegex = /(https?:\/\/)?(www\.)?youtube\.com\/live\/([A-Za-z0-9_-]+)/ const twitterSpaceRegex = /https:\/\/twitter\.com\/i\/spaces\/([A-Za-z0-9_-]+)/ const tweetUrlRegex = /https:\/\/twitter\.com\/[^/]+\/status\/(\d+)/ const mp3Regex = /(https?:\/\/)?([A-Za-z0-9_-]+)\.mp3/ @@ -10,21 +11,23 @@ const youtubeChannelPattern = /https?:\/\/(www\.)?youtube\.com\/(@)?([\w-]+)/i const genericUrlRegex = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/ export function getInputType(source: string) { - let inputType = DOCUMENT + let inputType = DOCUMENT; - if (youtubeRegex.test(source) || twitterSpaceRegex.test(source) || mp3Regex.test(source)) { - inputType = LINK + if (youtubeLiveRegex.test(source)) { + inputType = LINK; + } else if (youtubeRegex.test(source) || twitterSpaceRegex.test(source) || mp3Regex.test(source)) { + inputType = LINK; } else if (youtubeChannelPattern.test(source)) { - inputType = YOUTUBE_CHANNEL + inputType = YOUTUBE_CHANNEL; } else if (twitterHandlePattern.test(source)) { - inputType = TWITTER_HANDLE + inputType = TWITTER_HANDLE; } else if (tweetUrlRegex.test(source)) { - inputType = TWITTER_SOURCE + inputType = TWITTER_SOURCE; } else if (genericUrlRegex.test(source)) { - inputType = WEB_PAGE + inputType = WEB_PAGE; } - return inputType + return inputType; } export const extractNameFromLink = (inputString: string, type = ''): string | null => {