Nomad changes
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s

This commit is contained in:
Henrik Jess Nielsen
2026-06-01 23:40:55 +02:00
parent 72b1a0a6ed
commit b4c07d3693
5723 changed files with 1130655 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import type { ExtractionResult } from "@kreuzberg/wasm";
import { extractFromFile, initWasm } from "@kreuzberg/wasm";
async function _cacheResultInSessionStorage(file: File): Promise<ExtractionResult> {
await initWasm();
const cacheKey = `extraction_${file.name}_${file.size}`;
const cached = sessionStorage.getItem(cacheKey);
if (cached) {
console.log("Loading from session storage");
return JSON.parse(cached);
}
console.log("Extracting and caching result");
const result = await extractFromFile(file);
try {
sessionStorage.setItem(cacheKey, JSON.stringify(result));
} catch (error) {
if (error instanceof Error && error.name === "QuotaExceededError") {
console.warn("Session storage full, skipping cache");
}
}
return result;
}
async function clearExtractionCache() {
const keys = Object.keys(sessionStorage);
let cleared = 0;
for (const key of keys) {
if (key.startsWith("extraction_")) {
sessionStorage.removeItem(key);
cleared++;
}
}
console.log(`Cleared ${cleared} cached results`);
}
clearExtractionCache();