make the site mostly work when cookies (localStorage) are disabled

This commit is contained in:
Danny Coates 2017-08-09 18:16:10 -07:00
parent 493bf8dc89
commit 09faedf059
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
4 changed files with 47 additions and 10 deletions

View file

@ -1,8 +1,38 @@
const { isFile } = require('./utils');
class Mem {
constructor() {
this.items = new Map();
}
get length() {
return this.items.size;
}
getItem(key) {
return this.items.get(key);
}
setItem(key, value) {
return this.items.set(key, value);
}
removeItem(key) {
return this.items.delete(key);
}
key(i) {
return this.items.keys()[i];
}
}
class Storage {
constructor(engine) {
this.engine = engine;
constructor() {
try {
this.engine = localStorage || new Mem();
} catch (e) {
this.engine = new Mem();
}
}
get totalDownloads() {
@ -59,10 +89,6 @@ class Storage {
return this.engine.getItem(id);
}
has(property) {
return this.engine.hasOwnProperty(property);
}
remove(property) {
this.engine.removeItem(property);
}