chore: simplify kv values
This commit is contained in:
parent
52da6c6f39
commit
375d82c6f8
|
@ -5,26 +5,25 @@ export async function get(req) {
|
|||
const id = validateID(req.params.id);
|
||||
|
||||
// get times from KV
|
||||
const data = ((await KV.get(id)) || '|').split('|');
|
||||
const count = Number.parseInt(data[0]) || 0;
|
||||
const update = Number.parseInt(data[1]) || null;
|
||||
const count = Number.parseInt(await KV.get(id)) || 0;
|
||||
|
||||
return new Response(JSON.stringify({ count, update }), {
|
||||
return new Response(JSON.stringify({ count }), {
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function del(req) {
|
||||
const id = validateID(req.params.id);
|
||||
|
||||
await KV.delete(id);
|
||||
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Cache-Control': 'no-cache',
|
||||
},
|
||||
});
|
||||
|
|
|
@ -43,11 +43,10 @@ export async function get(req, event) {
|
|||
}
|
||||
|
||||
// get times from KV
|
||||
const data = ((await KV.get(id)) || '|').split('|');
|
||||
const count = (Number.parseInt(data[0]) || 0) + 1;
|
||||
const count = (Number.parseInt(await KV.get(id)) || 0) + 1;
|
||||
const image = genImage(count, theme, _length);
|
||||
// set time asynchronously (no await)
|
||||
event.waitUntil(KV.put(id, `${count}|${Date.now()}`));
|
||||
event.waitUntil(KV.put(id, count.toString()));
|
||||
|
||||
return new Response(image, {
|
||||
headers: {
|
||||
|
|
Loading…
Reference in New Issue