fix storage proxy and delete clear-site-data header

This commit is contained in:
Avad3 2024-07-13 08:52:02 -04:00
parent 263ceaa5e9
commit bc9a16720e
3 changed files with 17 additions and 6 deletions

View file

@ -18,6 +18,9 @@ const cspHeaders = [
"x-permitted-cross-domain-policies",
"x-powered-by",
"x-xss-protection",
// This needs to be emulated, but for right now it isn't that important of a feature to be worried about
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Clear-Site-Data
"clear-site-data"
];
const urlHeaders = [

View file

@ -1,12 +1,16 @@
import IDBMapSync from "@webreflection/idb-map/sync";
const store = new IDBMapSync(window.__location.host, {
prefix: "Storage",
durability: "relaxed"
});
await store.sync();
function storageProxy(scope: Storage): Storage {
const store = new IDBMapSync(window.__location.host);
return new Proxy(scope, {
async get(target, prop) {
await store.sync();
get(target, prop) {
switch (prop) {
case "getItem":
return (key: string) => {
@ -35,11 +39,14 @@ function storageProxy(scope: Storage): Storage {
case "length":
return store.size;
default:
return store.get(prop);
}
},
defineProperty(target, property, attributes) {
target.setItem(property as string, attributes.value);
store.set(property as string, attributes.value);
return true;
},

View file

@ -3,8 +3,9 @@
// "allowJs": true,
"allowImportingTsExtensions": true,
"rootDir": "./src",
"target": "ES2020",
"target": "ES2022",
"moduleResolution": "Bundler",
"module": "ES2022",
"noEmit": true
}
}