implement legacy url conversion

This commit is contained in:
castdrian 2023-06-13 14:06:37 +02:00
parent baf744b5d6
commit e889eaebaa
2 changed files with 32 additions and 1 deletions

View File

@ -163,3 +163,18 @@ export function decodeMWId(
id, id,
}; };
} }
export async function convertLegacyUrl(
url: string
): Promise<string | undefined> {
if (url.startsWith("/media/JW")) {
const urlParts = url.split("/").slice(2);
const [, type, id] = urlParts[0].split("-", 3);
const meta = await getLegacyMetaFromId(TTVMediaToMediaType(type), id);
if (!meta) return undefined;
const tmdbId = meta.tmdbId;
if (!tmdbId) return undefined;
return `/media/MW-${type}-${tmdbId}`;
}
return undefined;
}

View File

@ -1,6 +1,13 @@
import { lazy } from "react"; import { lazy } from "react";
import { Redirect, Route, Switch } from "react-router-dom"; import {
Redirect,
Route,
Switch,
useHistory,
useLocation,
} from "react-router-dom";
import { convertLegacyUrl } from "@/backend/metadata/getmeta";
import { MWMediaType } from "@/backend/metadata/types"; import { MWMediaType } from "@/backend/metadata/types";
import { BannerContextProvider } from "@/hooks/useBanner"; import { BannerContextProvider } from "@/hooks/useBanner";
import { Layout } from "@/setup/Layout"; import { Layout } from "@/setup/Layout";
@ -13,6 +20,15 @@ import { V2MigrationView } from "@/views/other/v2Migration";
import { SearchView } from "@/views/search/SearchView"; import { SearchView } from "@/views/search/SearchView";
function App() { function App() {
const location = useLocation();
const history = useHistory();
// Call the conversion function and redirect if necessary
convertLegacyUrl(location.pathname).then((convertedUrl) => {
if (convertedUrl) {
history.replace(convertedUrl);
}
});
return ( return (
<SettingsProvider> <SettingsProvider>
<WatchedContextProvider> <WatchedContextProvider>