From 4a7c18e3e81cfebdbdb4e02055de38d0763c06f7 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Fri, 1 Dec 2023 23:23:06 +0100 Subject: [PATCH] Re-implement disallowed ids in v4 --- src/pages/parts/player/MetaPart.tsx | 33 +++++++++++++++++++++++++++++ src/setup/config.ts | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/pages/parts/player/MetaPart.tsx b/src/pages/parts/player/MetaPart.tsx index 2e8ea13e..1101542c 100644 --- a/src/pages/parts/player/MetaPart.tsx +++ b/src/pages/parts/player/MetaPart.tsx @@ -13,11 +13,19 @@ import { Loading } from "@/components/layout/Loading"; import { Paragraph } from "@/components/text/Paragraph"; import { Title } from "@/components/text/Title"; import { ErrorContainer, ErrorLayout } from "@/pages/layouts/ErrorLayout"; +import { conf } from "@/setup/config"; export interface MetaPartProps { onGetMeta?: (meta: DetailedMeta, episodeId?: string) => void; } +function isDisallowedMedia(id: string, type: MWMediaType): boolean { + const disallowedEntries = conf().DISALLOWED_IDS.map((v) => v.split("-")); + if (disallowedEntries.find((entry) => id === entry[1] && type === entry[0])) + return true; + return false; +} + export function MetaPart(props: MetaPartProps) { const { t } = useTranslation(); const params = useParams<{ @@ -36,6 +44,8 @@ export function MetaPart(props: MetaPartProps) { } if (!data) return null; + if (isDisallowedMedia(data.id, data.type)) throw new Error("dmca"); + let meta: AsyncReturnType = null; try { meta = await getMetaFromId(data.type, data.id, params.season); @@ -68,6 +78,29 @@ export function MetaPart(props: MetaPartProps) { props.onGetMeta?.(meta, epId); }, []); + if (error && error.message === "dmca") { + return ( + + + Removed + Media has been removed + + This media is no longer available due to a takedown notice or + copyright claim. + + + + + ); + } + if (error) { return ( diff --git a/src/setup/config.ts b/src/setup/config.ts index 1af75305..1a908174 100644 --- a/src/setup/config.ts +++ b/src/setup/config.ts @@ -67,6 +67,7 @@ export function conf(): RuntimeConfig { NORMAL_ROUTER: getKey("NORMAL_ROUTER", "false") === "true", DISALLOWED_IDS: getKey("DISALLOWED_IDS", "") .split(",") - .map((v) => v.trim()), // Should be comma-seperated and contain the media type and ID, formatted like so: movie-753342,movie-753342,movie-753342 + .map((v) => v.trim()) + .filter((v) => v.length > 0), // Should be comma-seperated and contain the media type and ID, formatted like so: movie-753342,movie-753342,movie-753342 }; }