Skip to content

Commit b422301

Browse files
committed
Add CryptoKeyCacheEntry to allowed types to store in IndexedDB
1 parent 499426e commit b422301

12 files changed

+1217
-1049
lines changed

dist/browser/idb-cache.js

+43-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/idb-cache.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/idb-cache.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/idb-cache.js

+36-8
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,28 @@ function canUseBlob() {
2020
return true;
2121
}
2222

23+
class CryptoKeyCacheEntry {
24+
get length() {
25+
return this._length;
26+
}
27+
get key() {
28+
return this._key;
29+
}
30+
get id() {
31+
return this._id;
32+
}
33+
constructor(id, key, length) {
34+
this._id = id;
35+
this._key = key;
36+
this._length = length;
37+
}
38+
}
39+
2340
/**
2441
* @author Drecom Co.,Ltd. http://www.drecom.co.jp/
42+
*
43+
* Modified by Swisscom (Schweiz) AG (David Rupp)
44+
* -> Forked and enhanced with CryptoKeyCacheEntry
2545
*/
2646
const VERSION = 1;
2747
const STORE_NAME = {
@@ -32,10 +52,11 @@ const DATA_TYPE = {
3252
STRING: 1,
3353
ARRAYBUFFER: 2,
3454
BLOB: 3,
55+
CRYPTO_KEY: 4
3556
};
3657
const useBlob = canUseBlob();
3758
class IDBCache {
38-
constructor(dbName, strageLimit) {
59+
constructor(dbName, storageLimit) {
3960
this._maxSize = 52428800; // 50MB
4061
this._maxCount = 100; // 100files
4162
this._defaultAge = 86400; // 1day
@@ -47,13 +68,13 @@ class IDBCache {
4768
console.error('IndexedDB is not supported');
4869
return;
4970
}
50-
if (strageLimit) {
51-
if (strageLimit.size)
52-
this._maxSize = strageLimit.size;
53-
if (strageLimit.count)
54-
this._maxCount = strageLimit.count;
55-
if (strageLimit.defaultAge)
56-
this._defaultAge = strageLimit.defaultAge;
71+
if (storageLimit) {
72+
if (storageLimit.size)
73+
this._maxSize = storageLimit.size;
74+
if (storageLimit.count)
75+
this._maxCount = storageLimit.count;
76+
if (storageLimit.defaultAge)
77+
this._defaultAge = storageLimit.defaultAge;
5778
}
5879
this._initialize();
5980
}
@@ -393,6 +414,10 @@ class IDBCache {
393414
meta.type = DATA_TYPE.BLOB;
394415
meta.size = data.size;
395416
}
417+
else if (data instanceof CryptoKeyCacheEntry) {
418+
meta.type = DATA_TYPE.CRYPTO_KEY;
419+
meta.size = data.length;
420+
}
396421
else {
397422
console.warn('Is not supported type of value');
398423
}
@@ -426,6 +451,9 @@ class IDBCache {
426451
else if (data instanceof Blob) {
427452
type = DATA_TYPE.BLOB;
428453
}
454+
else if (data instanceof CryptoKeyCacheEntry) {
455+
type = DATA_TYPE.CRYPTO_KEY;
456+
}
429457
if (meta && meta.type === DATA_TYPE.BLOB && type === DATA_TYPE.ARRAYBUFFER) {
430458
const blob = new Blob([data], { type: meta.mime });
431459
cb(blob);

0 commit comments

Comments
 (0)