From 134dfcb5a29b3b4a5793ffb9f1215eda2fd26957 Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Mon, 26 May 2025 22:46:13 +1000 Subject: [PATCH] feat: remove background migration --- src/manifests/manifest.json | 2 +- src/seqta/utils/migration/migrate.html | 10 -- src/seqta/utils/migration/migration-iframe.ts | 137 ------------------ vite.config.ts | 8 - 4 files changed, 1 insertion(+), 156 deletions(-) delete mode 100644 src/seqta/utils/migration/migrate.html delete mode 100644 src/seqta/utils/migration/migration-iframe.ts diff --git a/src/manifests/manifest.json b/src/manifests/manifest.json index 06bd6669..9520c126 100644 --- a/src/manifests/manifest.json +++ b/src/manifests/manifest.json @@ -32,7 +32,7 @@ ], "web_accessible_resources": [ { - "resources": ["resources/icons/*", "seqta/utils/migration/migrate.html"], + "resources": ["resources/icons/*"], "matches": ["*://*/*"] } ] diff --git a/src/seqta/utils/migration/migrate.html b/src/seqta/utils/migration/migrate.html deleted file mode 100644 index 9eff2e31..00000000 --- a/src/seqta/utils/migration/migrate.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Background Migration - - - - - diff --git a/src/seqta/utils/migration/migration-iframe.ts b/src/seqta/utils/migration/migration-iframe.ts deleted file mode 100644 index c431ea5b..00000000 --- a/src/seqta/utils/migration/migration-iframe.ts +++ /dev/null @@ -1,137 +0,0 @@ -// This goes in your migration.html's script -interface Data { - id: string; - blob: Blob; - type: "image" | "video"; -} - -const openDB = (): Promise => { - return new Promise((resolve, reject) => { - const request = indexedDB.open("MyDatabase", 1); - request.onerror = () => reject(request.error); - request.onsuccess = () => resolve(request.result); - }); -}; - -const blobToBase64 = (blob: Blob): Promise => { - return new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onloadend = () => { - const base64 = reader.result as string; - resolve(base64.split(",")[1]); // Remove data URL prefix - }; - reader.onerror = () => reject(reader.error); - reader.readAsDataURL(blob); - }); -}; - -const getAllBackgrounds = async (): Promise => { - const db = await openDB(); - const tx = db.transaction("backgrounds", "readonly"); - const store = tx.objectStore("backgrounds"); - const request = store.getAll(); - - return new Promise((resolve, reject) => { - request.onsuccess = () => resolve(request.result); - request.onerror = () => reject(request.error); - }); -}; - -const getSelectedBackground = (): string | null => { - return localStorage.getItem("selectedBackground"); -}; - -const startMigration = async () => { - try { - console.info("Starting background extraction..."); - let backgrounds: Data[]; - try { - backgrounds = await getAllBackgrounds(); - if (!backgrounds || backgrounds.length === 0) { - console.info("No backgrounds to migrate"); - window.parent.postMessage({ type: "MIGRATION_COMPLETE" }, "*"); - return; - } - } catch (error: any) { - if ( - error.name === "NotFoundError" && - error.message.includes("object stores was not found") - ) { - console.info("No backgrounds to migrate: object store not found"); - window.parent.postMessage({ type: "MIGRATION_COMPLETE" }, "*"); - return; - } - console.error("Error fetching backgrounds:", error); - throw new Error("Failed to fetch backgrounds"); - } - const selectedBackground = getSelectedBackground(); - console.info(`Found ${backgrounds.length} backgrounds`); - - window.parent.postMessage({ type: "GET_LAST_PROCESSED_ID" }, "*"); - - const lastProcessedId = await new Promise((resolve) => { - const handler = (event: MessageEvent) => { - if (event.data.type === "LAST_PROCESSED_ID") { - window.removeEventListener("message", handler); - resolve(event.data.id); - } - }; - window.addEventListener("message", handler); - }); - - const remainingBackgrounds = lastProcessedId - ? backgrounds.slice( - backgrounds.findIndex((b) => b.id === lastProcessedId) + 1, - ) - : backgrounds; - - console.info( - `Processing ${remainingBackgrounds.length} remaining backgrounds`, - ); - - for (let i = 0; i < remainingBackgrounds.length; i++) { - const background = remainingBackgrounds[i]; - const base64Data = await blobToBase64(background.blob); - - window.parent.postMessage( - { - type: "BACKGROUND_DATA", - payload: { - id: background.id, - data: base64Data, - mediaType: background.type, - total: backgrounds.length, - processed: i + 1, - isSelected: background.id === selectedBackground, - }, - }, - "*", - ); - - await new Promise((resolve) => setTimeout(resolve, 100)); - } - - window.parent.postMessage({ type: "MIGRATION_COMPLETE" }, "*"); - } catch (error: any) { - console.error("Extraction failed:", error); - window.parent.postMessage( - { - type: "MIGRATION_ERROR", - error: error.message || "Unknown error", - }, - "*", - ); - } -}; - -window.addEventListener("message", (event) => { - switch (event.data.type) { - case "PING": - window.parent.postMessage({ type: "PONG" }, "*"); - break; - - case "START_MIGRATION": - startMigration(); - break; - } -}); diff --git a/vite.config.ts b/vite.config.ts index f3e9d1fd..f6b5a02a 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -81,14 +81,6 @@ export default defineConfig(({ command }) => ({ rollupOptions: { input: { settings: join(__dirname, "src", "interface", "index.html"), - migration: join( - __dirname, - "src", - "seqta", - "utils", - "migration", - "migrate.html", - ), pageState: join(__dirname, "src", "pageState.js"), }, },