inference-playground / src /lib /state /images.svelte.ts
Thomas G. Lopes
IndexedDb & Structured output (#82)
1778c9e unverified
raw
history blame contribute delete
648 Bytes
import { compressBase64Image, fileToDataURL } from "$lib/utils/file.js";
import { JsonEntityIndexedDbStorage } from "$lib/remult.js";
const store = new JsonEntityIndexedDbStorage();
class Images {
async upload(file: File) {
const dataUrl = await fileToDataURL(file);
const compressed = await compressBase64Image({ base64: dataUrl, maxSizeKB: 400 });
const key = `image-${crypto.randomUUID()}`;
store.setItem(key, compressed);
return key;
}
async get(key: string): Promise<string> {
return await store.getItem(key);
}
async delete(key: string) {
return await store.deleteItem(key);
}
}
export const images = new Images();