fix bugs, improve loading time

This commit is contained in:
Mystikfluu
2022-08-25 17:35:17 +02:00
parent 988d90b46f
commit d9fe8f2642
7 changed files with 31 additions and 18 deletions
+9 -3
View File
@@ -1,7 +1,7 @@
export const setup = function (router, con, server) {
const PIDS = {}; //[pid]: true/"already_used"
router.get("/api/pid", async function (req, res) {
res.set("Access-Control-Allow-Origin", "*");
function createPID(){
let pid = server.genstring(10); //collision chance is low enough, but we'll check anyways
while (PIDS[pid] != undefined) {
pid = server.genstring(10);
@@ -11,7 +11,12 @@ export const setup = function (router, con, server) {
setTimeout(function() {
PIDS[pid] = undefined;
}, 40000);
res.json({ "pid": pid });
return pid
}
router.get("/api/pid", async function (req, res) {
res.set("Access-Control-Allow-Origin", "*");
res.json({ "pid": createPID() });
});
router.post("/api/post", async function (req, res) {
if (!req.body.message) {
@@ -87,6 +92,7 @@ export const setup = function (router, con, server) {
console.log(5, `posted new message by ${res.locals.username} : ${req.body.message}`);
});
});
return createPID
};
export default {
setup