38 lines
820 B
TypeScript
Raw Normal View History

import { createVersionedStore } from "@/utils/storage";
import { OldData, migrateV2Videos } from "./migrations/v2";
2023-06-22 10:47:14 +02:00
import { migrateV3Videos } from "./migrations/v3";
import { WatchedStoreData } from "./types";
2023-02-11 01:05:27 +01:00
export const VideoProgressStore = createVersionedStore<WatchedStoreData>()
2023-02-11 01:05:27 +01:00
.setKey("video-progress")
.addVersion({
version: 0,
2023-01-12 22:04:28 +01:00
migrate() {
2023-01-12 22:36:28 +01:00
return {
items: [], // dont migrate from version 0 to version 1, unmigratable
2023-01-12 22:36:28 +01:00
};
},
2023-01-10 22:43:27 +01:00
})
.addVersion({
version: 1,
async migrate(old: OldData) {
2023-02-12 14:03:50 +01:00
return migrateV2Videos(old);
2023-01-10 22:43:27 +01:00
},
})
.addVersion({
version: 2,
migrate(old: WatchedStoreData) {
2023-06-22 10:47:14 +02:00
return migrateV3Videos(old);
},
})
.addVersion({
version: 3,
create() {
return {
items: [],
};
},
})
.build();