mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +00:00
fix KV emulation ttl
This commit is contained in:
parent
961cdab975
commit
e25b9c96c6
1 changed files with 8 additions and 8 deletions
|
@ -26,16 +26,16 @@ class KVShim {
|
||||||
|
|
||||||
makeValue(value, expirationTtl) {
|
makeValue(value, expirationTtl) {
|
||||||
if (!expirationTtl) {
|
if (!expirationTtl) {
|
||||||
return {
|
return JSON.stringify({
|
||||||
value,
|
value,
|
||||||
expires: false,
|
expires: false,
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return JSON.stringify({
|
||||||
value: JSON.stringify(value),
|
value,
|
||||||
expires: Date.now() + 1000 * expirationTtl,
|
expires: Date.now() + 1000 * expirationTtl,
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
validate(value) {
|
validate(value) {
|
||||||
|
@ -43,7 +43,7 @@ class KVShim {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.expires < Date.now()) {
|
if (value.expires && value.expires < Date.now()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class KVShim {
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(key, type = 'text') {
|
async get(key, type = 'text') {
|
||||||
const result = await this.level.get(key);
|
const result = JSON.parse(await this.level.get(key));
|
||||||
|
|
||||||
if (!this.validate(result)) {
|
if (!this.validate(result)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -75,7 +75,7 @@ class KVShim {
|
||||||
hasWarned = true;
|
hasWarned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.level.put(key, this.makeValue(value, expirationTtl));
|
return await this.level.put(key, this.makeValue(value, expirationTtl));
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(key) {
|
async delete(key) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue