feat: PDF in neue Tab öffnen und die PDFs werden in indexedDB gespeichert und dann von dort aufgerufen und gelesen mit Hilfe von idb Bibliothek

"npm install idb"
This commit is contained in:
ISA
2024-10-18 10:58:51 +02:00
parent 50cf1d3cea
commit 563105c79a
4 changed files with 129 additions and 4 deletions

19
utils/indexedDB.js Normal file
View File

@@ -0,0 +1,19 @@
import { openDB } from "idb";
const dbPromise = openDB("my-pdf-store", 1, {
upgrade(db) {
if (!db.objectStoreNames.contains("pdfs")) {
db.createObjectStore("pdfs");
}
},
});
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);
}