rename gesundheit, implement add operation
This commit is contained in:
parent
102c270b78
commit
7b096fe79a
@ -1,18 +1,17 @@
|
|||||||
export class Gesundheit {
|
export class AssetStore {
|
||||||
static #isInternalConstructing = false;
|
static #isInternalConstructing = false;
|
||||||
static #idb = globalThis.indexedDB;
|
static #idb = globalThis.indexedDB;
|
||||||
|
|
||||||
constructor(db) {
|
constructor(db) {
|
||||||
if (!Gesundheit.#isInternalConstructing) {
|
if (!AssetStore.#isInternalConstructing) {
|
||||||
throw new TypeError("Gesundheit is not constructable - use Gesundheit.load()");
|
throw new TypeError("Gesundheit is not constructable - use Gesundheit.load()");
|
||||||
}
|
}
|
||||||
Gesundheit.#isInternalConstructing = false;
|
AssetStore.#isInternalConstructing = false;
|
||||||
|
|
||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
async doSomethingOrOtter() {
|
async add(name, mime, bytes) {
|
||||||
console.log(this.db.objectStoreNames);
|
|
||||||
const transaction = this.db.transaction(["asset"], "readwrite");
|
const transaction = this.db.transaction(["asset"], "readwrite");
|
||||||
|
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
@ -24,12 +23,9 @@ export class Gesundheit {
|
|||||||
reject();
|
reject();
|
||||||
};
|
};
|
||||||
|
|
||||||
const assetStore = transaction.objectStore("asset");
|
const objectStore = transaction.objectStore("asset");
|
||||||
const _req = assetStore.add({
|
|
||||||
name: "idk",
|
objectStore.add({ name, mime, bytes });
|
||||||
mime: "idk",
|
|
||||||
bytes: [],
|
|
||||||
}, "asset");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,12 +41,9 @@ export class Gesundheit {
|
|||||||
req.onupgradeneeded = () => {
|
req.onupgradeneeded = () => {
|
||||||
const db = req.result;
|
const db = req.result;
|
||||||
|
|
||||||
const assetStore = db.createObjectStore("asset", {
|
db.createObjectStore("asset", {
|
||||||
keyPath: "name",
|
keyPath: "name",
|
||||||
});
|
});
|
||||||
|
|
||||||
assetStore.createIndex("mime", "mime", { unique: false });
|
|
||||||
assetStore.createIndex("bytes", "bytes", { unique: false });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
req.onsuccess = () => {
|
req.onsuccess = () => {
|
||||||
@ -58,6 +51,6 @@ export class Gesundheit {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
this.#isInternalConstructing = true;
|
this.#isInternalConstructing = true;
|
||||||
return new Gesundheit(db);
|
return new AssetStore(db);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ import { TextCompleter } from "./text_completer.js";
|
|||||||
import { ConsoleInput } from "./console_input.js";
|
import { ConsoleInput } from "./console_input.js";
|
||||||
import { downloadFile, slugify } from "./utils.js";
|
import { downloadFile, slugify } from "./utils.js";
|
||||||
import { HtmlExporter } from "./html_exporter.js";
|
import { HtmlExporter } from "./html_exporter.js";
|
||||||
import { Gesundheit } from "./gesundheit.js";
|
import { AssetStore } from "./asset_store.js";
|
||||||
|
|
||||||
const editor = ace.edit("editor");
|
const editor = ace.edit("editor");
|
||||||
editor.setTheme("ace/theme/gruvbox");
|
editor.setTheme("ace/theme/gruvbox");
|
||||||
@ -154,6 +154,6 @@ addEventListener("keydown", (ev) => {
|
|||||||
|
|
||||||
toggleAssetEditorButton.addEventListener("click", () => assetEditor.toggleEditor());
|
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", []);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user