From 430b9564ab3224176b42baa5e13d1216f033cc15 Mon Sep 17 00:00:00 2001 From: adrifcastr Date: Fri, 23 Jun 2023 09:35:07 +0200 Subject: [PATCH] remove duplicate code --- package.json | 1 + src/backend/metadata/getmeta.ts | 21 ------------------- src/components/media/MediaCard.tsx | 2 +- .../popouts/EpisodeSelectionPopout.tsx | 3 ++- src/views/media/MediaView.tsx | 7 ++----- yarn.lock | 5 +++++ 6 files changed, 11 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 3f7c4bf9..0aff05cf 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "react-stickynode": "^4.1.0", "react-transition-group": "^4.4.5", "react-use": "^17.4.0", + "slugify": "^1.6.6", "subsrt-ts": "^2.1.1", "unpacker": "^1.0.1" }, diff --git a/src/backend/metadata/getmeta.ts b/src/backend/metadata/getmeta.ts index c09d8292..a0fea637 100644 --- a/src/backend/metadata/getmeta.ts +++ b/src/backend/metadata/getmeta.ts @@ -180,27 +180,6 @@ export async function getLegacyMetaFromId( }; } -export function TMDBMediaToId(media: MWMediaMeta): string { - return ["tmdb", mediaTypeToTMDB(media.type), media.id].join("-"); -} - -export function decodeTMDBId( - paramId: string -): { id: string; type: MWMediaType } | null { - const [prefix, type, id] = paramId.split("-", 3); - if (prefix !== "tmdb") return null; - let mediaType; - try { - mediaType = TMDBMediaToMediaType(type); - } catch { - return null; - } - return { - type: mediaType, - id, - }; -} - export function isLegacyUrl(url: string): boolean { if (url.startsWith("/media/JW")) return true; return false; diff --git a/src/components/media/MediaCard.tsx b/src/components/media/MediaCard.tsx index a153d8b4..e05fbebb 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 { TMDBMediaToId } from "@/backend/metadata/getmeta"; +import { TMDBMediaToId } from "@/backend/metadata/tmdb"; import { MWMediaMeta } from "@/backend/metadata/types/mw"; import { DotList } from "@/components/text/DotList"; diff --git a/src/video/components/popouts/EpisodeSelectionPopout.tsx b/src/video/components/popouts/EpisodeSelectionPopout.tsx index 66c9ae49..a315a7d7 100644 --- a/src/video/components/popouts/EpisodeSelectionPopout.tsx +++ b/src/video/components/popouts/EpisodeSelectionPopout.tsx @@ -2,7 +2,8 @@ import { useCallback, useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { useParams } from "react-router-dom"; -import { decodeTMDBId, getMetaFromId } from "@/backend/metadata/getmeta"; +import { getMetaFromId } from "@/backend/metadata/getmeta"; +import { decodeTMDBId } from "@/backend/metadata/tmdb"; import { MWMediaType, MWSeasonWithEpisodeMeta, diff --git a/src/views/media/MediaView.tsx b/src/views/media/MediaView.tsx index 6e1659a6..ada4f9f8 100644 --- a/src/views/media/MediaView.tsx +++ b/src/views/media/MediaView.tsx @@ -4,11 +4,8 @@ import { useTranslation } from "react-i18next"; import { useHistory, useParams } from "react-router-dom"; import { MWStream } from "@/backend/helpers/streams"; -import { - DetailedMeta, - decodeTMDBId, - getMetaFromId, -} from "@/backend/metadata/getmeta"; +import { DetailedMeta, getMetaFromId } from "@/backend/metadata/getmeta"; +import { decodeTMDBId } from "@/backend/metadata/tmdb"; import { MWMediaType, MWSeasonWithEpisodeMeta, diff --git a/yarn.lock b/yarn.lock index a811afd3..5d687f2a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4764,6 +4764,11 @@ slice-ansi@^5.0.0: ansi-styles "^6.0.0" is-fullwidth-code-point "^4.0.0" +slugify@^1.6.6: + version "1.6.6" + resolved "https://registry.yarnpkg.com/slugify/-/slugify-1.6.6.tgz#2d4ac0eacb47add6af9e04d3be79319cbcc7924b" + integrity sha512-h+z7HKHYXj6wJU+AnS/+IH8Uh9fdcX1Lrhg1/VMdf9PwoBQXFcXiAdsy2tSK0P6gKwJLXp02r90ahUCqHk9rrw== + source-map-js@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"