From 867884a4d23d9cb53f4f3cdfc4e303d281a384f0 Mon Sep 17 00:00:00 2001 From: Enstrayed <48845980+Enstrayed@users.noreply.github.com> Date: Wed, 15 Nov 2023 11:44:47 -0800 Subject: [PATCH] add usage logging for premium services --- config.example.json | 3 ++- routes/azure.js | 3 +++ routes/cider.js | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config.example.json b/config.example.json index 65ec315..05905d6 100644 --- a/config.example.json +++ b/config.example.json @@ -17,7 +17,8 @@ "connectionString": "", "senderAddress": "apinotifications@enstrayed.com", - "authKeyInDb": "apiAuthKeys.azure" + "authKeyInDb": "apiAuthKeys.azure", + "usageKeyPrefix": "apiUsage.azure." } } \ No newline at end of file diff --git a/routes/azure.js b/routes/azure.js index 7828e5b..bbe3669 100644 --- a/routes/azure.js +++ b/routes/azure.js @@ -30,7 +30,10 @@ app.post("/sendemail", (rreq,rres) => { }, } + + azureEmail.beginSend(message).then(ares => { + db.incr(`${globalConfig.azure.usageKeyPrefix}${rreq.get("Authorization")}`) console.log(`${rreq.get("cf-connecting-ip")} POST /sendemail returned 200 KEY:${rreq.get("Authorization")}`) rres.sendStatus(200) }).catch(err => { diff --git a/routes/cider.js b/routes/cider.js index eaa2527..edd5fa2 100644 --- a/routes/cider.js +++ b/routes/cider.js @@ -43,6 +43,7 @@ app.post("/cider", (rreq,rres) => { // POST stop listening on cider target fetch(`http://${globalConfig.cider.targetHost}:${globalConfig.cider.targetPort}/stop`).then(fres => { // send GET /stop to cider target if (fres.status == 204) { + console.log(`${rreq.get("cf-connecting-ip")} POST /cider returned 200 KEY:${rreq.get("Authorization")}`) rres.sendStatus(200) // if that works then 200 } else { rres.sendStatus(500) // otherwise lol