mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-29 16:07:40 +01:00
implement legacy url conversion
This commit is contained in:
parent
70f8355386
commit
879271c239
2 changed files with 32 additions and 1 deletions
|
@ -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;
|
||||||
|
}
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue