mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-21 14:47:41 +01:00
refactor to initial prefix choice
This commit is contained in:
parent
879271c239
commit
b5c330d4e3
4 changed files with 11 additions and 11 deletions
|
@ -143,15 +143,15 @@ export async function getLegacyMetaFromId(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function MWMediaToId(media: MWMediaMeta): string {
|
export function TTVMediaToId(media: MWMediaMeta): string {
|
||||||
return ["MW", mediaTypeToTTV(media.type), media.id].join("-");
|
return ["TTV", mediaTypeToTTV(media.type), media.id].join("-");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function decodeMWId(
|
export function decodeTTVId(
|
||||||
paramId: string
|
paramId: string
|
||||||
): { id: string; type: MWMediaType } | null {
|
): { id: string; type: MWMediaType } | null {
|
||||||
const [prefix, type, id] = paramId.split("-", 3);
|
const [prefix, type, id] = paramId.split("-", 3);
|
||||||
if (prefix !== "MW") return null;
|
if (prefix !== "TTV") return null;
|
||||||
let mediaType;
|
let mediaType;
|
||||||
try {
|
try {
|
||||||
mediaType = TTVMediaToMediaType(type);
|
mediaType = TTVMediaToMediaType(type);
|
||||||
|
@ -174,7 +174,7 @@ export async function convertLegacyUrl(
|
||||||
if (!meta) return undefined;
|
if (!meta) return undefined;
|
||||||
const tmdbId = meta.tmdbId;
|
const tmdbId = meta.tmdbId;
|
||||||
if (!tmdbId) return undefined;
|
if (!tmdbId) return undefined;
|
||||||
return `/media/MW-${type}-${tmdbId}`;
|
return `/media/TTV-${type}-${tmdbId}`;
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Link } from "react-router-dom";
|
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 { MWMediaMeta } from "@/backend/metadata/types";
|
||||||
import { DotList } from "@/components/text/DotList";
|
import { DotList } from "@/components/text/DotList";
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ export function MediaCard(props: MediaCardProps) {
|
||||||
const canLink = props.linkable && !props.closable;
|
const canLink = props.linkable && !props.closable;
|
||||||
|
|
||||||
let link = canLink
|
let link = canLink
|
||||||
? `/media/${encodeURIComponent(MWMediaToId(props.media))}`
|
? `/media/${encodeURIComponent(TTVMediaToId(props.media))}`
|
||||||
: "#";
|
: "#";
|
||||||
if (canLink && props.series)
|
if (canLink && props.series)
|
||||||
link += `/${encodeURIComponent(props.series.seasonId)}/${encodeURIComponent(
|
link += `/${encodeURIComponent(props.series.seasonId)}/${encodeURIComponent(
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { useCallback, useMemo, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useParams } from "react-router-dom";
|
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 { MWMediaType, MWSeasonWithEpisodeMeta } from "@/backend/metadata/types";
|
||||||
import { IconPatch } from "@/components/buttons/IconPatch";
|
import { IconPatch } from "@/components/buttons/IconPatch";
|
||||||
import { Icon, Icons } from "@/components/Icon";
|
import { Icon, Icons } from "@/components/Icon";
|
||||||
|
@ -44,7 +44,7 @@ export function EpisodeSelectionPopout() {
|
||||||
seasonId: sId,
|
seasonId: sId,
|
||||||
season: undefined,
|
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;
|
if (v?.meta.type !== MWMediaType.SERIES) return;
|
||||||
setCurrentVisibleSeason({
|
setCurrentVisibleSeason({
|
||||||
seasonId: sId,
|
seasonId: sId,
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { useHistory, useParams } from "react-router-dom";
|
||||||
import { MWStream } from "@/backend/helpers/streams";
|
import { MWStream } from "@/backend/helpers/streams";
|
||||||
import {
|
import {
|
||||||
DetailedMeta,
|
DetailedMeta,
|
||||||
decodeMWId,
|
decodeTTVId,
|
||||||
getMetaFromId,
|
getMetaFromId,
|
||||||
} from "@/backend/metadata/getmeta";
|
} from "@/backend/metadata/getmeta";
|
||||||
import { MWMediaType, MWSeasonWithEpisodeMeta } from "@/backend/metadata/types";
|
import { MWMediaType, MWSeasonWithEpisodeMeta } from "@/backend/metadata/types";
|
||||||
|
@ -184,7 +184,7 @@ export function MediaView() {
|
||||||
const [selected, setSelected] = useState<SelectedMediaData | null>(null);
|
const [selected, setSelected] = useState<SelectedMediaData | null>(null);
|
||||||
const [exec, loading, error] = useLoading(
|
const [exec, loading, error] = useLoading(
|
||||||
async (mediaParams: string, seasonId?: string) => {
|
async (mediaParams: string, seasonId?: string) => {
|
||||||
const data = decodeMWId(mediaParams);
|
const data = decodeTTVId(mediaParams);
|
||||||
if (!data) return null;
|
if (!data) return null;
|
||||||
return getMetaFromId(data.type, data.id, seasonId);
|
return getMetaFromId(data.type, data.id, seasonId);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue