mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-29 16:07:40 +01:00
Merge pull request #2 from JamesHawkinss/v2/migration
Local storage migration
This commit is contained in:
commit
863bf31836
4 changed files with 76 additions and 86 deletions
|
@ -1,45 +1,13 @@
|
|||
import { versionedStoreBuilder } from 'utils/storage';
|
||||
|
||||
/*
|
||||
version 0
|
||||
{
|
||||
[{scraperid}]: {
|
||||
movie: {
|
||||
[{movie-id}]: {
|
||||
full: {
|
||||
currentlyAt: number,
|
||||
totalDuration: number,
|
||||
updatedAt: number, // unix timestamp in ms
|
||||
meta: FullMetaObject, // no idea whats in here
|
||||
}
|
||||
}
|
||||
},
|
||||
show: {
|
||||
[{show-id}]: {
|
||||
[{season}-{episode}]: {
|
||||
currentlyAt: number,
|
||||
totalDuration: number,
|
||||
updatedAt: number, // unix timestamp in ms
|
||||
show: {
|
||||
episode: string,
|
||||
season: string,
|
||||
},
|
||||
meta: FullMetaObject, // no idea whats in here
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
export const BookmarkStore = versionedStoreBuilder()
|
||||
.setKey('mw-bookmarks')
|
||||
.addVersion({
|
||||
version: 0,
|
||||
create() {
|
||||
return {
|
||||
bookmarks: []
|
||||
}
|
||||
.setKey('mw-bookmarks')
|
||||
.addVersion({
|
||||
version: 0,
|
||||
create() {
|
||||
return {
|
||||
bookmarks: []
|
||||
}
|
||||
})
|
||||
.build()
|
||||
}
|
||||
})
|
||||
.build()
|
||||
|
|
|
@ -14,7 +14,7 @@ interface WatchedStoreItem extends MWMediaMeta {
|
|||
percentage: number;
|
||||
}
|
||||
|
||||
interface WatchedStoreData {
|
||||
export interface WatchedStoreData {
|
||||
items: WatchedStoreItem[];
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ export function getWatchedFromPortable(
|
|||
}
|
||||
|
||||
const WatchedContext = createContext<WatchedStoreDataWrapper>({
|
||||
updateProgress: () => {},
|
||||
updateProgress: () => { },
|
||||
getFilteredWatched: () => [],
|
||||
watched: {
|
||||
items: [],
|
||||
|
|
|
@ -1,36 +1,6 @@
|
|||
import { MWMediaType } from "providers";
|
||||
import { versionedStoreBuilder } from "utils/storage";
|
||||
|
||||
/*
|
||||
version 0
|
||||
{
|
||||
[{scraperid}]: {
|
||||
movie: {
|
||||
[{movie-id}]: {
|
||||
full: {
|
||||
currentlyAt: number,
|
||||
totalDuration: number,
|
||||
updatedAt: number, // unix timestamp in ms
|
||||
meta: FullMetaObject, // no idea whats in here
|
||||
}
|
||||
}
|
||||
},
|
||||
show: {
|
||||
[{show-id}]: {
|
||||
[{season}-{episode}]: {
|
||||
currentlyAt: number,
|
||||
totalDuration: number,
|
||||
updatedAt: number, // unix timestamp in ms
|
||||
show: {
|
||||
episode: string,
|
||||
season: string,
|
||||
},
|
||||
meta: FullMetaObject, // no idea whats in here
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
import { WatchedStoreData } from "./context";
|
||||
|
||||
export const VideoProgressStore = versionedStoreBuilder()
|
||||
.setKey("video-progress")
|
||||
|
@ -40,7 +10,59 @@ export const VideoProgressStore = versionedStoreBuilder()
|
|||
.addVersion({
|
||||
version: 1,
|
||||
migrate(data: any) {
|
||||
// TODO migration
|
||||
const output: WatchedStoreData = { items: [] };
|
||||
|
||||
if (!data || data.constructor !== Object)
|
||||
return output;
|
||||
|
||||
Object.keys(data).forEach((scraperId) => {
|
||||
if (scraperId === "--version") return;
|
||||
if (scraperId === "save") return;
|
||||
|
||||
if (data[scraperId].movie && data[scraperId].movie.constructor === Object) {
|
||||
Object.keys(data[scraperId].movie).forEach((movieId) => {
|
||||
try {
|
||||
output.items.push({
|
||||
mediaId: movieId.includes("player.php") ? movieId.split("player.php%3Fimdb%3D")[1] : movieId,
|
||||
mediaType: MWMediaType.MOVIE,
|
||||
providerId: scraperId,
|
||||
title: data[scraperId].movie[movieId].full.meta.title,
|
||||
year: data[scraperId].movie[movieId].full.meta.year,
|
||||
progress: data[scraperId].movie[movieId].full.currentlyAt,
|
||||
percentage: Math.round((data[scraperId].movie[movieId].full.currentlyAt / data[scraperId].movie[movieId].full.totalDuration) * 100)
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(`Failed to migrate movie: ${scraperId}/${movieId}`, data[scraperId].movie[movieId]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (data[scraperId].show && data[scraperId].show.constructor === Object) {
|
||||
Object.keys(data[scraperId].show).forEach((showId) => {
|
||||
if (data[scraperId].show[showId].constructor !== Object)
|
||||
return;
|
||||
Object.keys(data[scraperId].show[showId]).forEach((episodeId) => {
|
||||
try {
|
||||
output.items.push({
|
||||
mediaId: showId,
|
||||
mediaType: MWMediaType.SERIES,
|
||||
providerId: scraperId,
|
||||
title: data[scraperId].show[showId][episodeId].meta.title,
|
||||
year: data[scraperId].show[showId][episodeId].meta.year,
|
||||
percentage: Math.round((data[scraperId].show[showId][episodeId].currentlyAt / data[scraperId].show[showId][episodeId].totalDuration) * 100),
|
||||
progress: data[scraperId].show[showId][episodeId].currentlyAt,
|
||||
episodeId: data[scraperId].show[showId][episodeId].show.episode,
|
||||
seasonId: data[scraperId].show[showId][episodeId].show.season,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(`Failed to migrate series: ${scraperId}/${showId}/${episodeId}`, data[scraperId].show[showId][episodeId]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return output;
|
||||
},
|
||||
create() {
|
||||
return {
|
||||
|
|
|
@ -157,19 +157,19 @@ export function versionedStoreBuilder(): any {
|
|||
version, // version number
|
||||
update: migrate
|
||||
? (data: any) => {
|
||||
// update function, and increment version
|
||||
migrate(data);
|
||||
data["--version"] = version; // eslint-disable-line no-param-reassign
|
||||
return data;
|
||||
}
|
||||
// update function, and increment version
|
||||
const newData = migrate(data);
|
||||
newData["--version"] = version; // eslint-disable-line no-param-reassign
|
||||
return newData;
|
||||
}
|
||||
: undefined,
|
||||
init: create
|
||||
? () => {
|
||||
// return an initial object
|
||||
const data = create();
|
||||
data["--version"] = version;
|
||||
return data;
|
||||
}
|
||||
// return an initial object
|
||||
const data = create();
|
||||
data["--version"] = version;
|
||||
return data;
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
return this;
|
||||
|
|
Loading…
Reference in a new issue