mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
holy cow
This commit is contained in:
@@ -9,11 +9,13 @@ import type {
|
||||
SerializedScene,
|
||||
} from "./types";
|
||||
import { SavedSoundsData, SavedSound, SoundEffect } from "@/types/sounds";
|
||||
import { migrations, runStorageMigrations } from "@/lib/migrations";
|
||||
|
||||
class StorageService {
|
||||
private projectsAdapter: IndexedDBAdapter<SerializedProject>;
|
||||
private savedSoundsAdapter: IndexedDBAdapter<SavedSoundsData>;
|
||||
private config: StorageConfig;
|
||||
private migrationsPromise: Promise<void> | null = null;
|
||||
|
||||
constructor() {
|
||||
this.config = {
|
||||
@@ -36,6 +38,18 @@ class StorageService {
|
||||
);
|
||||
}
|
||||
|
||||
private async ensureMigrations(): Promise<void> {
|
||||
if (this.migrationsPromise) {
|
||||
await this.migrationsPromise;
|
||||
return;
|
||||
}
|
||||
|
||||
this.migrationsPromise = runStorageMigrations({ migrations }).then(
|
||||
() => undefined,
|
||||
);
|
||||
await this.migrationsPromise;
|
||||
}
|
||||
|
||||
private getProjectMediaAdapters({ projectId }: { projectId: string }) {
|
||||
const mediaMetadataAdapter = new IndexedDBAdapter<MediaAssetData>(
|
||||
`${this.config.mediaDb}-${projectId}`,
|
||||
@@ -81,10 +95,19 @@ class StorageService {
|
||||
}: {
|
||||
id: string;
|
||||
}): Promise<{ project: TProject } | null> {
|
||||
await this.ensureMigrations();
|
||||
const serializedProject = await this.projectsAdapter.get(id);
|
||||
|
||||
if (!serializedProject) return null;
|
||||
|
||||
console.log(
|
||||
"[storage] loadProject scenes",
|
||||
JSON.stringify({
|
||||
projectId: id,
|
||||
scenes: serializedProject.scenes ?? [],
|
||||
}),
|
||||
);
|
||||
|
||||
const scenes =
|
||||
serializedProject.scenes?.map((scene) => ({
|
||||
id: scene.id,
|
||||
@@ -134,6 +157,7 @@ class StorageService {
|
||||
}
|
||||
|
||||
async loadAllProjectsMetadata(): Promise<TProjectMetadata[]> {
|
||||
await this.ensureMigrations();
|
||||
const serializedProjects = await this.projectsAdapter.getAll();
|
||||
|
||||
const metadata = serializedProjects.map((serializedProject) => ({
|
||||
|
||||
Reference in New Issue
Block a user