Fix not getting youtube video id from url
This commit is contained in:
@ -11,7 +11,7 @@ const YOUTUBE_URL_MATCH =
|
||||
|
||||
function getYoutubeVideoId(url) {
|
||||
const u = new URL(url);
|
||||
const videoId = u.searchParams['v']
|
||||
const videoId = u.searchParams.get('v');
|
||||
if (!videoId) {
|
||||
const match = url.toString().match(YOUTUBE_URL_MATCH)
|
||||
if (match === null || match.length < 6 || !match[5]) {
|
||||
@ -24,13 +24,10 @@ function getYoutubeVideoId(url) {
|
||||
exports.getYoutubeVideoId = getYoutubeVideoId
|
||||
|
||||
exports.youtubeHandler = {
|
||||
|
||||
shouldPrehandle: (url, env) => {
|
||||
return YOUTUBE_URL_MATCH.test(url.toString())
|
||||
},
|
||||
|
||||
|
||||
|
||||
prehandle: async (url, env) => {
|
||||
const videoId = getYoutubeVideoId(url)
|
||||
if (!videoId) {
|
||||
|
||||
@ -10,27 +10,24 @@ const YOUTUBE_URL_MATCH =
|
||||
/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/
|
||||
|
||||
function getYoutubeVideoId(url) {
|
||||
const u = new URL(url);
|
||||
const videoId = u.searchParams['v']
|
||||
if (!videoId) {
|
||||
const match = url.toString().match(YOUTUBE_URL_MATCH)
|
||||
if (match === null || match.length < 6 || !match[5]) {
|
||||
return undefined
|
||||
}
|
||||
return match[5]
|
||||
const u = new URL(url);
|
||||
const videoId = u.searchParams.get('v');
|
||||
if (!videoId) {
|
||||
const match = url.toString().match(YOUTUBE_URL_MATCH)
|
||||
if (match === null || match.length < 6 || !match[5]) {
|
||||
return undefined
|
||||
}
|
||||
return videoId
|
||||
return match[5]
|
||||
}
|
||||
return videoId
|
||||
}
|
||||
exports.getYoutubeVideoId = getYoutubeVideoId
|
||||
|
||||
exports.youtubeHandler = {
|
||||
|
||||
shouldPrehandle: (url, env) => {
|
||||
return YOUTUBE_URL_MATCH.test(url.toString())
|
||||
},
|
||||
|
||||
|
||||
|
||||
prehandle: async (url, env) => {
|
||||
const videoId = getYoutubeVideoId(url)
|
||||
if (!videoId) {
|
||||
|
||||
Reference in New Issue
Block a user