Skip to content

Commit

Permalink
Add support for Youtube Shorts URLs in the front-end
Browse files Browse the repository at this point in the history
  • Loading branch information
Anahkiasen committed Oct 11, 2023
1 parent 74c35f2 commit 4e460fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/pages/VideoLinkAddModal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ALLOWED_VIDEO_SOURCES_REGEX } from '@/pages/VideoLinkAddModal';

describe('ALLOWED_VIDEO_SOURCES_REGEX', () => {
const tests = {
'https://www.youtube.com/watch?v=12345678901': true,
'http://youtu.be/12345678901?si=6N2ks_X0YOE_0Pmg': true,
'https://www.youtube.com/shorts/ViOS7SeT0HE': true,
'https://vimeo.com/789006133': true,
'http://www.vimeo.com/789006133': true,
'http://miveo.com/789006133': false,
};

test.each(Object.entries(tests))(
'can test whether video URL %p being valid is %p',
(url, expected) =>
expect(ALLOWED_VIDEO_SOURCES_REGEX.test(url)).toBe(expected),
);
});
4 changes: 2 additions & 2 deletions src/pages/VideoLinkAddModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Props = {
};

const ALLOWED_VIDEO_SOURCES_REGEX: RegExp =
/^http(s?):\/\/(www\.)?((youtube\.com\/watch\?v=([^/#&?]*))|(vimeo\.com\/([^/#&?]*))|(youtu\.be\/([^/#&?]*)))/;
/^http(s?):\/\/(www\.)?((youtube\.com\/(watch\?v=|shorts\/)([^/#&?]*))|(vimeo\.com\/([^/#&?]*))|(youtu\.be\/([^/#&?]*)))/;

type FormData = {
link: string;
Expand Down Expand Up @@ -87,4 +87,4 @@ const VideoLinkAddModal = ({ visible, onConfirm, onClose }: Props) => {
);
};

export { VideoLinkAddModal };
export { ALLOWED_VIDEO_SOURCES_REGEX, VideoLinkAddModal };

0 comments on commit 4e460fa

Please sign in to comment.