diff options
Diffstat (limited to 'apps/web/src/services/storage/migrations/version-manager.ts')
| -rw-r--r-- | apps/web/src/services/storage/migrations/version-manager.ts | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/apps/web/src/services/storage/migrations/version-manager.ts b/apps/web/src/services/storage/migrations/version-manager.ts deleted file mode 100644 index 879498ce..00000000 --- a/apps/web/src/services/storage/migrations/version-manager.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { IndexedDBAdapter } from "@/services/storage/indexeddb-adapter"; - -type StorageVersionRecord = { - version: number; - inProgress?: { - from: number; - to: number; - }; -}; - -const DEFAULT_DB_NAME = "video-editor-meta"; -const DEFAULT_STORE_NAME = "storage-version"; -const DEFAULT_DB_VERSION = 1; -const STORAGE_VERSION_KEY = "storage-version"; - -export class StorageVersionManager { - private adapter: IndexedDBAdapter<StorageVersionRecord>; - - constructor({ - dbName = DEFAULT_DB_NAME, - storeName = DEFAULT_STORE_NAME, - version = DEFAULT_DB_VERSION, - }: { - dbName?: string; - storeName?: string; - version?: number; - } = {}) { - this.adapter = new IndexedDBAdapter<StorageVersionRecord>( - dbName, - storeName, - version, - ); - } - - async getVersion(): Promise<number> { - const record = await this.adapter.get(STORAGE_VERSION_KEY); - return record?.version ?? 0; - } - - async getVersionRecord(): Promise<StorageVersionRecord | null> { - return this.adapter.get(STORAGE_VERSION_KEY); - } - - async setVersion({ version }: { version: number }): Promise<void> { - const record = await this.getVersionRecord(); - const inProgress = record?.inProgress; - await this.adapter.set(STORAGE_VERSION_KEY, { - version, - ...(inProgress ? { inProgress } : {}), - }); - } - - async setInProgress({ - from, - to, - }: { - from: number; - to: number; - }): Promise<void> { - const record = await this.getVersionRecord(); - const version = record?.version ?? 0; - await this.adapter.set(STORAGE_VERSION_KEY, { - version, - inProgress: { from, to }, - }); - } - - async clearInProgress(): Promise<void> { - const record = await this.getVersionRecord(); - const version = record?.version ?? 0; - await this.adapter.set(STORAGE_VERSION_KEY, { version }); - } -} |
