41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import { openDB } from "idb"; // utils/indexedDB.js
|
|
|
|
const dbPromise = openDB("my-pdf-store", 1, {
|
|
upgrade(db) {
|
|
// Überprüfe und erstelle den Object Store für PDFs
|
|
if (!db.objectStoreNames.contains("pdfs")) {
|
|
db.createObjectStore("pdfs");
|
|
}
|
|
// Überprüfe und erstelle den Object Store für Seiten (pages)
|
|
if (!db.objectStoreNames.contains("pages")) {
|
|
db.createObjectStore("pages"); // Korrekte Erstellung des "pages" Object Stores
|
|
}
|
|
},
|
|
});
|
|
|
|
// Store PDF
|
|
export async function storePDF(name, file) {
|
|
const db = await dbPromise;
|
|
await db.put("pdfs", file, name);
|
|
}
|
|
|
|
export async function getPDF(name) {
|
|
const db = await dbPromise;
|
|
return await db.get("pdfs", name);
|
|
}
|
|
|
|
// Store page
|
|
export async function storePage(name, file) {
|
|
const db = await dbPromise;
|
|
// Überprüfe, ob der Object Store "pages" existiert
|
|
const transaction = db.transaction("pages", "readwrite");
|
|
const store = transaction.objectStore("pages");
|
|
await store.put(file, name);
|
|
await transaction.done;
|
|
}
|
|
|
|
export async function getPage(name) {
|
|
const db = await dbPromise;
|
|
return await db.get("pages", name);
|
|
}
|