From 9ecc648a03343bc7f2bd8568ade72661aff4e57e Mon Sep 17 00:00:00 2001 From: svetlagasheva Date: Mon, 1 Jun 2020 16:41:16 +0300 Subject: [PATCH] check for valid links added --- src/common/MetaPreview/MetaPreview.js | 61 ++++++++++++++------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/common/MetaPreview/MetaPreview.js b/src/common/MetaPreview/MetaPreview.js index b5f96c0a5..c96874f0a 100644 --- a/src/common/MetaPreview/MetaPreview.js +++ b/src/common/MetaPreview/MetaPreview.js @@ -27,44 +27,47 @@ const ALLOWED_LINK_REDIRECTS = [ const MetaPreview = ({ className, compact, name, logo, background, runtime, releaseInfo, released, description, links, trailer, inLibrary, toggleInLibrary }) => { const [shareModalOpen, openShareModal, closeShareModal] = useBinaryState(false); const linksGroups = React.useMemo(() => { - return links - .filter((link) => link && typeof link.category === 'string' && typeof link.url === 'string') - .reduce((linksGroups, { category, name, url }) => { - if (category === CONSTANTS.IMDB_LINK_CATEGORY) { - linksGroups.set(category, { - label: name, - href: `https://www.stremio.com/warning#${encodeURIComponent(`https://www.imdb.com/title/${encodeURIComponent(url)}`)}` - }); - } else if (category === CONSTANTS.SHARE_LINK_CATEGORY) { - linksGroups.set(category, { - label: name, - href: url - }); - } else { - const { protocol, host, path, pathname } = UrlUtils.parse(url); - if (protocol === 'stremio:') { - if (pathname !== null && ALLOWED_LINK_REDIRECTS.some((regexp) => pathname.match(regexp))) { + return Array.isArray(links) ? + links + .filter((link) => link && typeof link.category === 'string' && typeof link.url === 'string') + .reduce((linksGroups, { category, name, url }) => { + if (category === CONSTANTS.IMDB_LINK_CATEGORY) { + linksGroups.set(category, { + label: name, + href: `https://www.stremio.com/warning#${encodeURIComponent(`https://www.imdb.com/title/${encodeURIComponent(url)}`)}` + }); + } else if (category === CONSTANTS.SHARE_LINK_CATEGORY) { + linksGroups.set(category, { + label: name, + href: url + }); + } else { + const { protocol, host, path, pathname } = UrlUtils.parse(url); + if (protocol === 'stremio:') { + if (pathname !== null && ALLOWED_LINK_REDIRECTS.some((regexp) => pathname.match(regexp))) { + if (!linksGroups.has(category)) { + linksGroups.set(category, []); + } + linksGroups.get(category).push({ + label: name, + href: `#${path}` + }); + } + } else if (typeof host === 'string' && host.length > 0) { if (!linksGroups.has(category)) { linksGroups.set(category, []); } linksGroups.get(category).push({ label: name, - href: `#${path}` + href: `https://www.stremio.com/warning#${encodeURIComponent(url)}` }); } - } else if (typeof host === 'string' && host.length > 0) { - if (!linksGroups.has(category)) { - linksGroups.set(category, []); - } - linksGroups.get(category).push({ - label: name, - href: `https://www.stremio.com/warning#${encodeURIComponent(url)}` - }); } - } - return linksGroups; - }, new Map()); + return linksGroups; + }, new Map()) + : + new Map(); }, [links]); const trailerHref = React.useMemo(() => { if (typeof trailer !== 'object' || trailer === null) {