mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-11 02:25:08 +01:00
implement legacy url conversion
This commit is contained in:
parent
70f8355386
commit
879271c239
@ -163,3 +163,18 @@ export function decodeMWId(
|
||||
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;
|
||||
}
|
||||
|
@ -1,6 +1,13 @@
|
||||
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 { BannerContextProvider } from "@/hooks/useBanner";
|
||||
import { Layout } from "@/setup/Layout";
|
||||
@ -13,6 +20,15 @@ import { V2MigrationView } from "@/views/other/v2Migration";
|
||||
import { SearchView } from "@/views/search/SearchView";
|
||||
|
||||
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 (
|
||||
<SettingsProvider>
|
||||
<WatchedContextProvider>
|
||||
|
Loading…
Reference in New Issue
Block a user