Compare commits

...

3 commits

Author SHA1 Message Date
6a1c444770
Small fixes
All checks were successful
/ tests (pull_request) Successful in 20s
/ node-check (pull_request) Successful in 3s
/ prettier (pull_request) Successful in 16s
/ boot (pull_request) Successful in 20s
2024-05-26 16:39:27 +00:00
8985e25bac
Unrelated, but verify the namespace and key are actual valid before making them 2024-05-26 16:36:28 +00:00
ad4652c874
Validate key and namespace names 2024-05-26 16:29:12 +00:00

View file

@ -77,6 +77,7 @@ async function get_counter_value(ns_name, key, return_id = false) {
}
async function counter_increment(ns_name, key, offset, create = false) {
if (!valid_regex.test(key) || !valid_regex.test(ns_name)) return null;
var nsid = await get_namespace_id(ns_name);
return await sql.begin(async (sql) => {
if (offset == 0) return true;
@ -133,11 +134,21 @@ async function counter_set(ns_name, key, value) {
}
async function counter_info(ns_name, key) {
if (!valid_regex.test(key) || !valid_regex.test(ns_name))
return {
id: null,
namespace: null,
name: null,
value: null,
enable_reset: null,
update_lowerbound: null,
update_upperbound: null,
};
var nsid = get_namespace_id(ns_name);
if (nsid == null)
return {
id: null,
namespace_id: null,
namespace: null,
name: null,
value: null,
enable_reset: null,
@ -145,11 +156,11 @@ async function counter_info(ns_name, key) {
update_upperbound: null,
};
var data =
await sql`SELECT * FROM keys WHERE name = ${key} AND namespace_id = ${nsid}`;
await sql`SELECT id, name, value, enable_reset, update_lowerbound, update_upperbound FROM keys WHERE name = ${key} AND namespace_id = ${nsid}`;
if (data.length == 0)
return {
id: null,
namespace_id: null,
namespace: null,
name: null,
value: null,
enable_reset: null,
@ -158,6 +169,7 @@ async function counter_info(ns_name, key) {
};
var key = data[0];
if (typeof key.value === "string") key.value = parseInt(key.value);
key.namespace = ns_name;
return key;
}