Fixed missing responses
This commit is contained in:
260
server.cjs
260
server.cjs
@@ -1,4 +1,4 @@
|
||||
require('dotenv').config()
|
||||
require("dotenv").config();
|
||||
const express = require("express");
|
||||
const cors = require("cors");
|
||||
const fs = require("node:fs");
|
||||
@@ -58,7 +58,7 @@ function sqlEscape(str) {
|
||||
});
|
||||
}
|
||||
|
||||
// receiver = snmp.createReceiver(options, callback);
|
||||
const receiver = snmp.createReceiver(options, callback);
|
||||
|
||||
// initializing app
|
||||
const app = express();
|
||||
@@ -82,16 +82,21 @@ app.get("/trigger/api/personalData", async (req, res) => {
|
||||
});
|
||||
|
||||
app.patch("/trigger/api/personalData", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `UPDATE trigger_database.personalData SET firstName = '${sqlEscape(req.body.firstName)}', lastName = '${sqlEscape(req.body.lastName)}', email = '${sqlEscape(req.body.email)}';`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.get("/trigger/api/messages", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = "SELECT * FROM trigger_database.messages;";
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
@@ -100,34 +105,49 @@ app.get("/trigger/api/messages", async (req, res) => {
|
||||
});
|
||||
|
||||
app.post("/trigger/api/messages", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.messages (message) VALUES ('${sqlEscape(req.body.message)}');`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.patch("/trigger/api/messages", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `UPDATE trigger_database.messages SET message = '${sqlEscape(req.body.message)}' WHERE id = '${sqlEscape(req.body.id)}';`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.delete("/trigger/api/messages", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `DELETE FROM trigger_database.messages WHERE id = '${sqlEscape(req.body.id)}'`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.get("/trigger/api/apps", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = "SELECT * FROM trigger_database.apps;";
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
@@ -136,35 +156,51 @@ app.get("/trigger/api/apps", async (req, res) => {
|
||||
});
|
||||
|
||||
app.post("/trigger/api/apps", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.apps (name, url, icon, baseUrl, filterName) VALUES ('${sqlEscape(req.body.name)}', '${sqlEscape(req.body.url)}', '${sqlEscape(req.body.icon)}', '${sqlEscape(req.body.baseUrl)}', '${sqlEscape(req.body.filterName)}')`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.patch("/trigger/api/apps", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `UPDATE trigger_database.apps SET name = '${sqlEscape(req.body.name)}', url = '${sqlEscape(req.body.url)}', icon = '${sqlEscape(req.body.icon)}', baseUrl = '${sqlEscape(req.body.baseUrl)}', category = '${sqlEscape(req.body.filterName)}' WHERE id = '${req.body.id}'`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.delete("/trigger/api/apps", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `DELETE FROM trigger_database.apps WHERE id = '${sqlEscape(req.body.id)}'`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.get("/trigger/api/appCategories", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const query = "SELECT filterName FROM trigger_database.apps UNION SELECT filterName FROM trigger_database.linkCategories;";
|
||||
const conn = await pool.getConnection();
|
||||
const query =
|
||||
"SELECT filterName FROM trigger_database.apps UNION SELECT filterName FROM trigger_database.linkCategories;";
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
});
|
||||
@@ -172,7 +208,7 @@ app.get("/trigger/api/appCategories", async (req, res) => {
|
||||
});
|
||||
|
||||
app.get("/trigger/api/links", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = "SELECT * FROM trigger_database.links;";
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
@@ -181,34 +217,49 @@ app.get("/trigger/api/links", async (req, res) => {
|
||||
});
|
||||
|
||||
app.post("/trigger/api/links", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.links (name, url, category) VALUES ('${sqlEscape(req.body.name)}', '${sqlEscape(req.body.url)}', '${sqlEscape(req.body.category)}')`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.patch("/trigger/api/links", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `UPDATE trigger_database.links SET name = '${sqlEscape(req.body.name)}', url = '${sqlEscape(req.body.url)}', category = '${sqlEscape(req.body.category)}' WHERE id = '${req.body.id}'`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.delete("/trigger/api/links", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `DELETE FROM trigger_database.links WHERE id = '${req.body.id}'`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.get("/trigger/api/providers", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = "SELECT * FROM trigger_database.providers;";
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
@@ -217,34 +268,49 @@ app.get("/trigger/api/providers", async (req, res) => {
|
||||
});
|
||||
|
||||
app.post("/trigger/api/providers", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.providers (name, url, prefix) VALUES ('${sqlEscape(req.body.name)}', '${req.body.url}', '${req.body.prefix}')`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.patch("/trigger/api/providers", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `UPDATE trigger_database.providers SET name = '${sqlEscape(req.body.name)}', url = '${sqlEscape(req.body.url)}', prefix = '${sqlEscape(req.body.prefix)}' WHERE id = '${req.body.id}'`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.delete("/trigger/api/providers", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `DELETE FROM trigger_database.providers WHERE id = '${req.body.id}'`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.get("/trigger/api/themes", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = "SELECT * FROM trigger_database.themes;";
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
@@ -253,34 +319,49 @@ app.get("/trigger/api/themes", async (req, res) => {
|
||||
});
|
||||
|
||||
app.post("/trigger/api/themes", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.themes (name, backgroundImage, backgroundColor, searchColor, primaryColor, accentColor, borderColor) VALUES ('${sqlEscape(req.body.name)}','${sqlEscape(req.body.backgroundImage)}','${req.body.backgroundColor}','${req.body.searchColor}','${req.body.primaryColor}','${req.body.accentColor}','${req.body.borderColor}')`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.patch("/trigger/api/themes", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `UPDATE trigger_database.themes SET name = '${sqlEscape(req.body.name)}', backgroundImage = '${sqlEscape(req.body.backgroundImage)}', backgroundColor = '${req.body.backgroundColor}', searchColor = '${req.body.searchColor}', primaryColor = '${req.body.primaryColor}', accentColor = '${req.body.accentColor}', borderColor = '${req.body.borderColor}', randomEnabled = '${req.body.randomEnabled ? 1 : 0}' WHERE id = '${req.body.id}';`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.delete("/trigger/api/themes", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `DELETE FROM trigger_database.themes WHERE id = '${req.body.id}'`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.get("/trigger/api/categories", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = "SELECT * from trigger_database.linkCategories;";
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
@@ -289,7 +370,7 @@ app.get("/trigger/api/categories", async (req, res) => {
|
||||
});
|
||||
|
||||
app.post("/trigger/api/categories", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
let conn = await pool.getConnection();
|
||||
let query = "SELECT * from trigger_database.linkCategories;";
|
||||
let categoryIndex;
|
||||
conn.query(query).then((rows) => {
|
||||
@@ -300,25 +381,36 @@ app.post("/trigger/api/categories", async (req, res) => {
|
||||
query = `INSERT INTO trigger_database.linkCategories (categoryName, categoryIndex, filterName) VALUES ('${sqlEscape(req.body.categoryName)}','${categoryIndex || 0}','${sqlEscape(req.body.filterName)}')`;
|
||||
conn.query(query).then((rows) => {
|
||||
categoryIndex = rows.length;
|
||||
res.status(200).send({ status: "success" });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.patch("/trigger/api/categories", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `UPDATE trigger_database.linkCategories SET categoryName = '${sqlEscape(req.body.categoryName)}', filterName = '${sqlEscape(req.body.filterName)}' WHERE id = '${req.body.id}';`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.delete("/trigger/api/categories", async (req, res) => {
|
||||
conn = await pool.getConnection();
|
||||
const conn = await pool.getConnection();
|
||||
const query = `DELETE FROM trigger_database.linkCategories WHERE id = '${req.body.id}'`;
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200);
|
||||
});
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
@@ -327,4 +419,4 @@ app.get("/trigger/api/wakeDakota", (req, res) => {
|
||||
});
|
||||
|
||||
// app is listening on port 5000
|
||||
app.listen(5000, '0.0.0.0', () => {});
|
||||
app.listen(5000, "0.0.0.0", () => {});
|
||||
|
||||
Reference in New Issue
Block a user