rename gesundheit, implement add operation

This commit is contained in:
Reimar 2025-10-14 09:09:19 +02:00
parent 102c270b78
commit 7b096fe79a
2 changed files with 12 additions and 19 deletions

View File

@ -1,18 +1,17 @@
export class Gesundheit {
export class AssetStore {
static #isInternalConstructing = false;
static #idb = globalThis.indexedDB;
constructor(db) {
if (!Gesundheit.#isInternalConstructing) {
if (!AssetStore.#isInternalConstructing) {
throw new TypeError("Gesundheit is not constructable - use Gesundheit.load()");
}
Gesundheit.#isInternalConstructing = false;
AssetStore.#isInternalConstructing = false;
this.db = db;
}
async doSomethingOrOtter() {
console.log(this.db.objectStoreNames);
async add(name, mime, bytes) {
const transaction = this.db.transaction(["asset"], "readwrite");
return await new Promise((resolve, reject) => {
@ -24,12 +23,9 @@ export class Gesundheit {
reject();
};
const assetStore = transaction.objectStore("asset");
const _req = assetStore.add({
name: "idk",
mime: "idk",
bytes: [],
}, "asset");
const objectStore = transaction.objectStore("asset");
objectStore.add({ name, mime, bytes });
});
}
@ -45,12 +41,9 @@ export class Gesundheit {
req.onupgradeneeded = () => {
const db = req.result;
const assetStore = db.createObjectStore("asset", {
db.createObjectStore("asset", {
keyPath: "name",
});
assetStore.createIndex("mime", "mime", { unique: false });
assetStore.createIndex("bytes", "bytes", { unique: false });
};
req.onsuccess = () => {
@ -58,6 +51,6 @@ export class Gesundheit {
};
});
this.#isInternalConstructing = true;
return new Gesundheit(db);
return new AssetStore(db);
}
}

View File

@ -14,7 +14,7 @@ import { TextCompleter } from "./text_completer.js";
import { ConsoleInput } from "./console_input.js";
import { downloadFile, slugify } from "./utils.js";
import { HtmlExporter } from "./html_exporter.js";
import { Gesundheit } from "./gesundheit.js";
import { AssetStore } from "./asset_store.js";
const editor = ace.edit("editor");
editor.setTheme("ace/theme/gruvbox");
@ -154,6 +154,6 @@ addEventListener("keydown", (ev) => {
toggleAssetEditorButton.addEventListener("click", () => assetEditor.toggleEditor());
const gsh = await Gesundheit.load("assetdb");
const assetStore = await AssetStore.load("assetdb");
await gsh.doSomethingOrOtter();
await assetStore.add("test", "image/png", []);