3 lines
2.7 KiB
JavaScript
3 lines
2.7 KiB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./CGmNF7c0.js","./Sa-_S7_w.js","./entry.DORe4TYg.css"])))=>i.map(i=>d[i]);
|
|
import{bX as w,bn as b,bY as d,bZ as l,b_ as p}from"./Sa-_S7_w.js";async function h(n,a="gzip"){let e;if(typeof Buffer<"u"){const i=Buffer.from(n,"base64");e=Uint8Array.from(i)}else if(typeof atob<"u")e=Uint8Array.from(atob(n),i=>i.charCodeAt(0));else throw new TypeError("No base64 decoding method available");const o=new Response(new Blob([e])).body?.pipeThrough(new DecompressionStream(a)),c=await new Response(o).text();return JSON.parse(c)}function f(n,a){const e=g(n),t={...a};for(const o in t)e[o]==="json"&&t[o]&&t[o]!=="undefined"&&(t[o]=JSON.parse(t[o])),e[o]==="boolean"&&t[o]!=="undefined"&&(t[o]=!!t[o]);for(const o in t)t[o]==="NULL"&&(t[o]=void 0);return t}function g(n){const a=n.match(/FROM\s+(\w+)/);return a?w[y(a[1])]?.fields||{}:{}}function y(n){return n.replace(/^_content_/,"")}let r;const u=new Map,s=new Map;function E(n){async function a(e){const t=String(e);return r||(s.has("_")||s.set("_",S()),r=await s.get("_"),s.delete("_")),u.has(t)||(s.has(t)||s.set(t,_(e)),await s.get(t),u.set(t,"loaded"),s.delete(t)),r}return{all:async(e,t)=>(await a(n),r.exec({sql:e,bind:t,rowMode:"object",returnValue:"resultRows"}).map(o=>f(e,o))),first:async(e,t)=>(await a(n),f(e,r.exec({sql:e,bind:t,rowMode:"object",returnValue:"resultRows"}).shift())),exec:async(e,t)=>{await a(n),await r.exec({sql:e,bind:t})}}}async function S(){if(!r){const n=await b(()=>import("./CGmNF7c0.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(e=>e.default);globalThis.sqlite3ApiConfig={silent:!0,debug:(...e)=>console.debug(...e),warn:(...e)=>{String(e[0]).includes("OPFS sqlite3_vfs")||console.warn(...e)},error:(...e)=>console.error(...e),log:(...e)=>console.log(...e)};const a=await n();r=new a.oo1.DB}return r}async function _(n){if(window.sessionStorage.getItem("previewToken"))return r;let a=null;const e=`checksum_${n}`,t=`collection_${n}`;let o="matched";try{r.exec({sql:`SELECT * FROM ${d.info} where id = '${e}'`,rowMode:"object",returnValue:"resultRows"}).shift()?.version!==l[String(n)]&&(o="mismatch")}catch{o="missing"}if(o!=="matched"){if(window.localStorage.getItem(`content_${e}`)===l[String(n)]&&(a=window.localStorage.getItem(`content_${t}`)),!a){a=await p(void 0,String(n));try{window.localStorage.setItem(`content_${e}`,l[String(n)]),window.localStorage.setItem(`content_${t}`,a)}catch(i){console.error("Database integrity check failed, rebuilding database",i)}}const c=await h(a);await r.exec({sql:`DROP TABLE IF EXISTS ${d[String(n)]}`}),o==="mismatch"&&await r.exec({sql:`DELETE FROM ${d.info} WHERE id = '${e}'`});for(const i of c)try{await r.exec(i)}catch(m){console.error("Error executing command",m)}}return r}export{E as loadDatabaseAdapter};
|