-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
image-store.js
37 lines (27 loc) · 1.09 KB
/
image-store.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* global IDBFiles */
/* exported saveCollectedBlobs, loadStoredImages, removeStoredImages */
"use strict";
async function saveCollectedBlobs(collectionName, collectedBlobs) {
const storedImages = await IDBFiles.getFileStorage({name: "stored-images"});
for (const item of collectedBlobs) {
await storedImages.put(`${collectionName}/${item.uuid}`, item.blob);
}
}
async function loadStoredImages(filter) {
const imagesStore = await IDBFiles.getFileStorage({name: "stored-images"});
let listOptions = filter ? {includes: filter} : undefined;
const imagesList = await imagesStore.list(listOptions);
let storedImages = [];
for (const storedName of imagesList) {
const blob = await imagesStore.get(storedName);
storedImages.push({storedName, blobUrl: URL.createObjectURL(blob)});
}
return storedImages;
}
async function removeStoredImages(storedImages) {
const imagesStore = await IDBFiles.getFileStorage({name: "stored-images"});
for (const storedImage of storedImages) {
URL.revokeObjectURL(storedImage.blobUrl);
await imagesStore.remove(storedImage.storedName);
}
}