Compare commits

..

1 Commits

Author SHA1 Message Date
QuentinHsu
bac04587b8 🐞 fix(subscriptions): negative usage flow 2022-10-23 13:36:01 +08:00
3 changed files with 17 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.13.6",
"version": "2.13.5",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {

View File

@@ -16,13 +16,8 @@ class ResourceCache {
let clear = false;
Object.entries(this.resourceCache).forEach((entry) => {
const [id, updated] = entry;
if (!updated.time) {
// clear old version cache
delete this.resourceCache[id];
if (new Date().getTime() - updated > this.expires) {
$.delete(`#${id}`);
clear = true;
}
if (new Date().getTime() - updated.time > this.expires) {
delete this.resourceCache[id];
clear = true;
}
@@ -31,6 +26,9 @@ class ResourceCache {
}
revokeAll() {
Object.keys(this.resourceCache).forEach((id) => {
$.delete(`#${id}`);
});
this.resourceCache = {};
this._persist();
}
@@ -40,16 +38,17 @@ class ResourceCache {
}
get(id) {
const updated = this.resourceCache[id] && this.resourceCache[id].time;
const updated = this.resourceCache[id];
if (updated && new Date().getTime() - updated <= this.expires) {
return this.resourceCache[id].data;
return $.read(`#${id}`);
}
return null;
}
set(id, value) {
this.resourceCache[id] = { time: new Date().getTime(), data: value }
this.resourceCache[id] = new Date().getTime();
this._persist();
$.write(value, `#${id}`);
}
}

View File

@@ -17,13 +17,8 @@ class ResourceCache {
let clear = false;
Object.entries(this.resourceCache).forEach((entry) => {
const [id, updated] = entry;
if (!updated.time) {
// clear old version cache
delete this.resourceCache[id];
if (new Date().getTime() - updated > this.expires) {
$.delete(`#${id}`);
clear = true;
}
if (new Date().getTime() - updated.time > this.expires) {
delete this.resourceCache[id];
clear = true;
}
@@ -32,6 +27,9 @@ class ResourceCache {
}
revokeAll() {
Object.keys(this.resourceCache).forEach((id) => {
$.delete(`#${id}`);
});
this.resourceCache = {};
this._persist();
}
@@ -41,16 +39,17 @@ class ResourceCache {
}
get(id) {
const updated = this.resourceCache[id] && this.resourceCache[id].time;
const updated = this.resourceCache[id];
if (updated && new Date().getTime() - updated <= this.expires) {
return this.resourceCache[id].data;
return $.read(`#${id}`);
}
return null;
}
set(id, value) {
this.resourceCache[id] = { time: new Date().getTime(), data: value }
this.resourceCache[id] = new Date().getTime();
this._persist();
$.write(value, `#${id}`);
}
}