import { SQLITE3_WASM_BASE64 } from './sqlite3-wasm.ts'; import { FolderSyncDB } from '../../sqlite/src/index.ts'; import { initPasteApp } from '../shared.ts'; // Decode embedded WASM → blob URL so sqlite3InitModule loads // without fetch(), enabling file:// usage (no server needed). function base64ToBlob(b64: string, mime: string): Blob { const bin = atob(b64); const bytes = new Uint8Array(bin.length); for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i); return new Blob([bytes], { type: mime }); } const wasmBlobUrl = URL.createObjectURL( base64ToBlob(SQLITE3_WASM_BASE64, 'application/wasm'), ); document.addEventListener('DOMContentLoaded', async () => { try { const db = await FolderSyncDB.open({ autoSyncIntervalMs: 3000, sqlite3Config: { locateFile: (path: string) => path.endsWith('.wasm') ? wasmBlobUrl : path, }, }); await initPasteApp(db as any, 'sqlite'); } catch (e) { console.error('SQLite init failed:', e); document.body.innerHTML = `
SQLite init failed: ${(e as Error).message}
`; } });