mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +01:00
domain migrations
Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com>
This commit is contained in:
parent
4f682d55a9
commit
b43f39b007
6 changed files with 83 additions and 1166 deletions
|
@ -17,6 +17,7 @@
|
|||
"lodash.throttle": "^4.1.1",
|
||||
"nanoid": "^4.0.0",
|
||||
"ofetch": "^1.0.0",
|
||||
"pako": "^2.1.0",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-helmet": "^6.1.0",
|
||||
|
@ -54,6 +55,7 @@
|
|||
"@types/fscreen": "^1.0.1",
|
||||
"@types/lodash.throttle": "^4.1.7",
|
||||
"@types/node": "^17.0.15",
|
||||
"@types/pako": "^2.0.0",
|
||||
"@types/react": "^17.0.39",
|
||||
"@types/react-dom": "^17.0.11",
|
||||
"@types/react-router": "^5.1.18",
|
||||
|
|
|
@ -22,8 +22,6 @@ initializeChromecast();
|
|||
// TODO video todos:
|
||||
// - chrome cast support
|
||||
// - bug: safari fullscreen will make video overlap player controls
|
||||
// - improvement: make scrapers use fuzzy matching on normalized titles
|
||||
// - bug: .ass subtitle files are fucked
|
||||
|
||||
// TODO stuff to test:
|
||||
// - browser: firefox, chrome, edge, safari desktop
|
||||
|
@ -37,9 +35,6 @@ initializeChromecast();
|
|||
// - implement jons providers/embedscrapers
|
||||
// - AFTER all that: rank providers/embedscrapers
|
||||
|
||||
// TODO general todos:
|
||||
// - localize everything (fix loading screen text (series vs movies))
|
||||
|
||||
const LazyLoadedApp = React.lazy(async () => {
|
||||
await initializeStores();
|
||||
return {
|
||||
|
|
|
@ -6,12 +6,14 @@ import { NotFoundPage } from "@/views/notfound/NotFoundView";
|
|||
import { MediaView } from "@/views/media/MediaView";
|
||||
import { SearchView } from "@/views/search/SearchView";
|
||||
import { MWMediaType } from "@/backend/metadata/types";
|
||||
import { V2MigrationView } from "@/views/other/v2Migration";
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<WatchedContextProvider>
|
||||
<BookmarkContextProvider>
|
||||
<Switch>
|
||||
<Route exact path="/v2-migration" component={V2MigrationView} />
|
||||
<Route exact path="/">
|
||||
<Redirect to={`/search/${MWMediaType.MOVIE}`} />
|
||||
</Route>
|
||||
|
|
|
@ -148,6 +148,8 @@ export async function migrateV2Videos(old: OldData) {
|
|||
items: [],
|
||||
};
|
||||
|
||||
const now = Date.now();
|
||||
|
||||
for (const oldWatched of oldData.items) {
|
||||
if (oldWatched.mediaType === "movie") {
|
||||
if (!mediaMetas[oldWatched.mediaId]["0"]?.meta) continue;
|
||||
|
@ -186,8 +188,8 @@ export async function migrateV2Videos(old: OldData) {
|
|||
},
|
||||
progress: oldWatched.progress,
|
||||
percentage: oldWatched.percentage,
|
||||
watchedAt: Date.now(), // There was no watchedAt in V2
|
||||
// Put watchedAt in the future to show last episode as most recently
|
||||
watchedAt: now + Number(oldWatched.seasonId) * 1000 + Number(oldWatched.episodeId), // There was no watchedAt in V2
|
||||
// JANK ALERT: Put watchedAt in the future to show last episode as most recently
|
||||
};
|
||||
|
||||
if (
|
||||
|
|
61
src/views/other/v2Migration.tsx
Normal file
61
src/views/other/v2Migration.tsx
Normal file
|
@ -0,0 +1,61 @@
|
|||
import { useEffect, useState } from "react";
|
||||
import pako from "pako";
|
||||
|
||||
function fromBinary(str: string): Uint8Array {
|
||||
let result = new Uint8Array(str.length);
|
||||
[...str].forEach((char, i) => {
|
||||
result[i] = char.charCodeAt(0);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
export function V2MigrationView() {
|
||||
const [done, setDone] = useState(false);
|
||||
useEffect(() => {
|
||||
const params = new URLSearchParams(window.location.search ?? "");
|
||||
if (!params.has("m-time") || !params.has("m-data")) {
|
||||
// migration params missing, just redirect
|
||||
setDone(true);
|
||||
return;
|
||||
}
|
||||
|
||||
const data = JSON.parse(pako.inflate(fromBinary(atob(params.get("m-data") as string)), { to: "string" }));
|
||||
const timeOfMigration = new Date(params.get("m-time") as string);
|
||||
|
||||
const savedTime = localStorage.getItem("mw-migration-date");
|
||||
if (savedTime) {
|
||||
if (new Date(savedTime) >= timeOfMigration) {
|
||||
// has already migrated this or something newer, skip
|
||||
setDone(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// restore migration data
|
||||
if (data.bookmarks)
|
||||
localStorage.setItem("mw-bookmarks", JSON.stringify(data.bookmarks))
|
||||
if (data.videoProgress)
|
||||
localStorage.setItem("video-progress", JSON.stringify(data.videoProgress))
|
||||
localStorage.setItem("mw-migration-date", timeOfMigration.toISOString())
|
||||
|
||||
// finished
|
||||
setDone(true);
|
||||
}, [])
|
||||
|
||||
// redirect when done
|
||||
useEffect(() => {
|
||||
if (!done) return;
|
||||
const newUrl = new URL(window.location.href);
|
||||
|
||||
const newParams = [] as string[];
|
||||
newUrl.searchParams.forEach((_, key)=>newParams.push(key));
|
||||
newParams.forEach(v => newUrl.searchParams.delete(v))
|
||||
|
||||
newUrl.hash = "";
|
||||
|
||||
window.location.href = newUrl.toString();
|
||||
}, [done])
|
||||
|
||||
return null;
|
||||
}
|
Loading…
Reference in a new issue