From 5435c6b8a02e12a3b1bc2784bdd2ee9ba67e42be Mon Sep 17 00:00:00 2001 From: tgxn Date: Tue, 12 Mar 2024 19:11:28 +0800 Subject: [PATCH 1/2] grafana endpoint --- src/module/grafana.js | 45 +++++++++++++++++++++++++++++++++++++++++++ src/routes/push.js | 2 ++ 2 files changed, 47 insertions(+) create mode 100644 src/module/grafana.js diff --git a/src/module/grafana.js b/src/module/grafana.js new file mode 100644 index 0000000..a5a0ed4 --- /dev/null +++ b/src/module/grafana.js @@ -0,0 +1,45 @@ +const { getTopicBySecretKey } = require("../services/topic"); + +const { createPushToTopic, pushToTopicDevices } = require("../services/push"); + +const { appLogger } = require("../middleware/logging.js"); + +const createGrafanaPushRequest = async (request, response, next) => { + try { + console.log("inputPayload", request.body); + let { title, state, message } = request.body; + console.log("inputPayload", { title, state, message }); + + const pushPayload = { + categoryId: "simple.push", + title: `Grafana: ${title}`, + body: message, + }; + + const foundTopic = await getTopicBySecretKey(request.params.topicSecret); + if (!foundTopic) { + return next(new Error("Topic secret key does not exist")); + } + appLogger.debug("foundTopic", foundTopic.dataValues.id); + + const createdPush = await createPushToTopic(foundTopic); + appLogger.info("createPush", createdPush.dataValues); + + // respond early + response + .status(200) + .json({ + success: true, + pushIdent: createdPush.dataValues.pushIdent, + }) + .send(); + + await pushToTopicDevices(foundTopic, createdPush, pushPayload); + } catch (error) { + next(error); + } +}; + +module.exports = { + createGrafanaPushRequest, +}; diff --git a/src/routes/push.js b/src/routes/push.js index 851b162..4fe2425 100644 --- a/src/routes/push.js +++ b/src/routes/push.js @@ -12,6 +12,7 @@ const { } = require("../controllers/push"); const { createUpTimeKumaPushRequest } = require("../module/uptimekuma"); +const { createGrafanaPushRequest } = require("../module/grafana"); const router = express.Router(); @@ -21,6 +22,7 @@ router.get("/", authorize(), getUserPushHistory); // push to topic with secret router.post("/:topicSecret", createPushRequest); router.post("/:topicSecret/uptimekuma", createUpTimeKumaPushRequest); +router.post("/:topicSecret/grafana", createGrafanaPushRequest); // get information on a push request router.post("/:pushIdent/receipt", recordPushReceipt); // when the notification is recieved From 9266cc1b61f6664048c824d48a1c136503196dab Mon Sep 17 00:00:00 2001 From: tgxn Date: Wed, 3 Apr 2024 18:27:29 +0800 Subject: [PATCH 2/2] update compose, add delete html --- docker-compose.yaml | 1 - public/delete.html | 13 +++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 public/delete.html diff --git a/docker-compose.yaml b/docker-compose.yaml index de2e476..ba58d9a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,4 +1,3 @@ -version: "3.5" networks: pushme-net: diff --git a/public/delete.html b/public/delete.html new file mode 100644 index 0000000..f80ccad --- /dev/null +++ b/public/delete.html @@ -0,0 +1,13 @@ +

Account Deletion Policy

+

Last updated: April 03, 2024

+

+ You can delete your account via the app, on the "Settings" page. +

+

+ If you need help with this button, please contact us at the address below. Thanks. +

+

Contact Us

+

If you have any questions about this Policy, You can contact us:

+