mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-20 23:12:13 +00:00
check for valid links added
This commit is contained in:
parent
ca4e19339d
commit
9ecc648a03
1 changed files with 32 additions and 29 deletions
|
|
@ -27,44 +27,47 @@ const ALLOWED_LINK_REDIRECTS = [
|
||||||
const MetaPreview = ({ className, compact, name, logo, background, runtime, releaseInfo, released, description, links, trailer, inLibrary, toggleInLibrary }) => {
|
const MetaPreview = ({ className, compact, name, logo, background, runtime, releaseInfo, released, description, links, trailer, inLibrary, toggleInLibrary }) => {
|
||||||
const [shareModalOpen, openShareModal, closeShareModal] = useBinaryState(false);
|
const [shareModalOpen, openShareModal, closeShareModal] = useBinaryState(false);
|
||||||
const linksGroups = React.useMemo(() => {
|
const linksGroups = React.useMemo(() => {
|
||||||
return links
|
return Array.isArray(links) ?
|
||||||
.filter((link) => link && typeof link.category === 'string' && typeof link.url === 'string')
|
links
|
||||||
.reduce((linksGroups, { category, name, url }) => {
|
.filter((link) => link && typeof link.category === 'string' && typeof link.url === 'string')
|
||||||
if (category === CONSTANTS.IMDB_LINK_CATEGORY) {
|
.reduce((linksGroups, { category, name, url }) => {
|
||||||
linksGroups.set(category, {
|
if (category === CONSTANTS.IMDB_LINK_CATEGORY) {
|
||||||
label: name,
|
linksGroups.set(category, {
|
||||||
href: `https://www.stremio.com/warning#${encodeURIComponent(`https://www.imdb.com/title/${encodeURIComponent(url)}`)}`
|
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, {
|
} else if (category === CONSTANTS.SHARE_LINK_CATEGORY) {
|
||||||
label: name,
|
linksGroups.set(category, {
|
||||||
href: url
|
label: name,
|
||||||
});
|
href: url
|
||||||
} else {
|
});
|
||||||
const { protocol, host, path, pathname } = UrlUtils.parse(url);
|
} else {
|
||||||
if (protocol === 'stremio:') {
|
const { protocol, host, path, pathname } = UrlUtils.parse(url);
|
||||||
if (pathname !== null && ALLOWED_LINK_REDIRECTS.some((regexp) => pathname.match(regexp))) {
|
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)) {
|
if (!linksGroups.has(category)) {
|
||||||
linksGroups.set(category, []);
|
linksGroups.set(category, []);
|
||||||
}
|
}
|
||||||
linksGroups.get(category).push({
|
linksGroups.get(category).push({
|
||||||
label: name,
|
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;
|
return linksGroups;
|
||||||
}, new Map());
|
}, new Map())
|
||||||
|
:
|
||||||
|
new Map();
|
||||||
}, [links]);
|
}, [links]);
|
||||||
const trailerHref = React.useMemo(() => {
|
const trailerHref = React.useMemo(() => {
|
||||||
if (typeof trailer !== 'object' || trailer === null) {
|
if (typeof trailer !== 'object' || trailer === null) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue