From b5c330d4e3cd4b4aa77b3f3dc7cfcba02a785f7b Mon Sep 17 00:00:00 2001 From: castdrian Date: Tue, 13 Jun 2023 14:20:33 +0200 Subject: [PATCH] refactor to initial prefix choice --- src/backend/metadata/getmeta.ts | 10 +++++----- src/components/media/MediaCard.tsx | 4 ++-- .../components/popouts/EpisodeSelectionPopout.tsx | 4 ++-- src/views/media/MediaView.tsx | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/backend/metadata/getmeta.ts b/src/backend/metadata/getmeta.ts index b6f90f26..82b3c20b 100644 --- a/src/backend/metadata/getmeta.ts +++ b/src/backend/metadata/getmeta.ts @@ -143,15 +143,15 @@ export async function getLegacyMetaFromId( }; } -export function MWMediaToId(media: MWMediaMeta): string { - return ["MW", mediaTypeToTTV(media.type), media.id].join("-"); +export function TTVMediaToId(media: MWMediaMeta): string { + return ["TTV", mediaTypeToTTV(media.type), media.id].join("-"); } -export function decodeMWId( +export function decodeTTVId( paramId: string ): { id: string; type: MWMediaType } | null { const [prefix, type, id] = paramId.split("-", 3); - if (prefix !== "MW") return null; + if (prefix !== "TTV") return null; let mediaType; try { mediaType = TTVMediaToMediaType(type); @@ -174,7 +174,7 @@ export async function convertLegacyUrl( if (!meta) return undefined; const tmdbId = meta.tmdbId; if (!tmdbId) return undefined; - return `/media/MW-${type}-${tmdbId}`; + return `/media/TTV-${type}-${tmdbId}`; } return undefined; } diff --git a/src/components/media/MediaCard.tsx b/src/components/media/MediaCard.tsx index 3bac4d08..b87654a9 100644 --- a/src/components/media/MediaCard.tsx +++ b/src/components/media/MediaCard.tsx @@ -1,7 +1,7 @@ import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; -import { MWMediaToId } from "@/backend/metadata/getmeta"; +import { TTVMediaToId } from "@/backend/metadata/getmeta"; import { MWMediaMeta } from "@/backend/metadata/types"; import { DotList } from "@/components/text/DotList"; @@ -132,7 +132,7 @@ export function MediaCard(props: MediaCardProps) { const canLink = props.linkable && !props.closable; let link = canLink - ? `/media/${encodeURIComponent(MWMediaToId(props.media))}` + ? `/media/${encodeURIComponent(TTVMediaToId(props.media))}` : "#"; if (canLink && props.series) link += `/${encodeURIComponent(props.series.seasonId)}/${encodeURIComponent( diff --git a/src/video/components/popouts/EpisodeSelectionPopout.tsx b/src/video/components/popouts/EpisodeSelectionPopout.tsx index 3d0b431b..7ea6c5a3 100644 --- a/src/video/components/popouts/EpisodeSelectionPopout.tsx +++ b/src/video/components/popouts/EpisodeSelectionPopout.tsx @@ -2,7 +2,7 @@ import { useCallback, useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { useParams } from "react-router-dom"; -import { decodeMWId, getMetaFromId } from "@/backend/metadata/getmeta"; +import { decodeTTVId, getMetaFromId } from "@/backend/metadata/getmeta"; import { MWMediaType, MWSeasonWithEpisodeMeta } from "@/backend/metadata/types"; import { IconPatch } from "@/components/buttons/IconPatch"; import { Icon, Icons } from "@/components/Icon"; @@ -44,7 +44,7 @@ export function EpisodeSelectionPopout() { seasonId: sId, season: undefined, }); - reqSeasonMeta(decodeMWId(params.media)?.id as string, sId).then((v) => { + reqSeasonMeta(decodeTTVId(params.media)?.id as string, sId).then((v) => { if (v?.meta.type !== MWMediaType.SERIES) return; setCurrentVisibleSeason({ seasonId: sId, diff --git a/src/views/media/MediaView.tsx b/src/views/media/MediaView.tsx index 1a4709e3..c0e81455 100644 --- a/src/views/media/MediaView.tsx +++ b/src/views/media/MediaView.tsx @@ -6,7 +6,7 @@ import { useHistory, useParams } from "react-router-dom"; import { MWStream } from "@/backend/helpers/streams"; import { DetailedMeta, - decodeMWId, + decodeTTVId, getMetaFromId, } from "@/backend/metadata/getmeta"; import { MWMediaType, MWSeasonWithEpisodeMeta } from "@/backend/metadata/types"; @@ -184,7 +184,7 @@ export function MediaView() { const [selected, setSelected] = useState(null); const [exec, loading, error] = useLoading( async (mediaParams: string, seasonId?: string) => { - const data = decodeMWId(mediaParams); + const data = decodeTTVId(mediaParams); if (!data) return null; return getMetaFromId(data.type, data.id, seasonId); }