Pushing search history
This commit is contained in:
24
server.cjs
24
server.cjs
@@ -460,5 +460,29 @@ app.post("/trigger/api/wakeClient", async (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/trigger/api/searchHistory", async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query =
|
||||
"SELECT * FROM trigger_database.searchHistory ORDER BY dateTimeStamp DESC;";
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.post("/trigger/api/searchHistory", async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.searchHistory (prefix, provider, searchTerm) VALUES ('${sqlEscape(req.body.prefix)}', '${sqlEscape(req.body.provider)}', '${sqlEscape(req.body.searchTerm)}')`;
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
// app is listening on port 5000
|
||||
app.listen(5000, "0.0.0.0", () => {});
|
||||
|
||||
Reference in New Issue
Block a user