refactor: review changes to use existing youtube function

This commit is contained in:
Keith Grootboom
2023-03-15 14:07:57 +02:00
committed by Ken Clary
parent b4fb88c73c
commit 475c32463a
2 changed files with 3 additions and 8 deletions

View File

@@ -1,13 +1,8 @@
import messages from '../messages';
// https://stackoverflow.com/a/28735961/479084
const youtubeRegex = /^(?:https?:\/\/)?(?:m\.|www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;
function isYoutubeUrl(url) {
return url.match(youtubeRegex) !== null;
}
import { parseYoutubeId } from '../../../../../../data/services/cms/api';
function getVideoType(videoSource) {
if (isYoutubeUrl(videoSource)) {
if (parseYoutubeId(videoSource) !== null) {
return messages.videoTypeYoutube;
}
return messages.videoTypeOther;

View File

@@ -68,7 +68,7 @@ export const messages = {
},
videoTypeYoutube: {
id: 'authoring.videoeditor.videotype.youtube',
defaultMessage: 'Youtube video',
defaultMessage: 'YouTube video',
description: 'Shown on the preview card if the video is from youtube.com.',
},
videoTypeOther: {