Run prettier
All checks were successful
/ prettier (pull_request) Successful in 16s
/ boot (pull_request) Successful in 14s
/ node-check (pull_request) Successful in 3s
/ tests (pull_request) Successful in 20s
/ node-check (push) Successful in 3s
/ prettier (push) Successful in 28s
/ boot (push) Successful in 26s
/ tests (push) Successful in 44s
All checks were successful
/ prettier (pull_request) Successful in 16s
/ boot (pull_request) Successful in 14s
/ node-check (pull_request) Successful in 3s
/ tests (pull_request) Successful in 20s
/ node-check (push) Successful in 3s
/ prettier (push) Successful in 28s
/ boot (push) Successful in 26s
/ tests (push) Successful in 44s
This commit is contained in:
parent
9e5dac8dfb
commit
57a6494261
1 changed files with 14 additions and 15 deletions
29
index.js
29
index.js
|
@ -5,14 +5,14 @@ import { randomUUID } from "crypto";
|
||||||
const app = express();
|
const app = express();
|
||||||
const valid_regex = /^[A-Za-z0-9_\-\.]{3,64}$/;
|
const valid_regex = /^[A-Za-z0-9_\-\.]{3,64}$/;
|
||||||
var stats = {
|
var stats = {
|
||||||
keys_created: 0,
|
keys_created: 0,
|
||||||
keys_updated: 0,
|
keys_updated: 0,
|
||||||
requests: 0,
|
requests: 0,
|
||||||
version: "who knows?"
|
version: "who knows?",
|
||||||
};
|
};
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
stats.requests++;
|
stats.requests++;
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
|
|
||||||
async function get_namespace_id(name, create = true) {
|
async function get_namespace_id(name, create = true) {
|
||||||
|
@ -117,10 +117,9 @@ async function counter_increment(ns_name, key, offset, create = false) {
|
||||||
${offset < 0 ? sql`update_lowerbound <= ${offset}` : sql`update_upperbound >= ${offset}`}
|
${offset < 0 ? sql`update_lowerbound <= ${offset}` : sql`update_upperbound >= ${offset}`}
|
||||||
RETURNING value`;
|
RETURNING value`;
|
||||||
if (sql_res.length == 1) {
|
if (sql_res.length == 1) {
|
||||||
stats.keys_updated++;
|
stats.keys_updated++;
|
||||||
return parseInt(sql_res[0].value);
|
return parseInt(sql_res[0].value);
|
||||||
}
|
} else return null;
|
||||||
else return null;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,9 +131,9 @@ async function counter_update(ns_name, key, amount) {
|
||||||
await sql`SELECT value FROM keys WHERE name = ${key} AND namespace_id = ${nsid}`;
|
await sql`SELECT value FROM keys WHERE name = ${key} AND namespace_id = ${nsid}`;
|
||||||
if (res.length == 0) return null;
|
if (res.length == 0) return null;
|
||||||
else {
|
else {
|
||||||
stats.keys_updated++;
|
stats.keys_updated++;
|
||||||
return parseInt(res[0].value);
|
return parseInt(res[0].value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function counter_set(ns_name, key, value) {
|
async function counter_set(ns_name, key, value) {
|
||||||
|
@ -305,8 +304,8 @@ app.get("/create", async function (req, res) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/stats", function(req, res) {
|
app.get("/stats", function (req, res) {
|
||||||
return res.json(stats);
|
return res.json(stats);
|
||||||
});
|
});
|
||||||
|
|
||||||
const listen_path =
|
const listen_path =
|
||||||
|
|
Loading…
Reference in a new issue