Change post to get method
This commit is contained in:
37
src/index.js
37
src/index.js
@@ -6,6 +6,7 @@ import express from 'express';
|
||||
import Joi from 'joi';
|
||||
import TelegramBot from 'node-telegram-bot-api';
|
||||
import https from 'https';
|
||||
import axios from "axios";
|
||||
|
||||
const Logo = fs.readFileSync("./assets/Logo_fwaur.png", { encoding: "latin1" });
|
||||
const config = JSON.parse(fs.readFileSync("./config.json", "utf8"));
|
||||
@@ -174,30 +175,32 @@ const app = express();
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
app.post('/depesche', async (req, res) => {
|
||||
if (config.debug) {
|
||||
fs.writeFileSync(cacheFolder + req.body.foreign_id + "_body.json", JSON.stringify(req.body))
|
||||
}
|
||||
|
||||
app.get('/depesche', async (req, res) => {
|
||||
console.log("[INFO] Received print request");
|
||||
|
||||
if (req.body.foreign_id == "") {
|
||||
req.body.foreign_id = "undefined"
|
||||
}
|
||||
|
||||
let value = {}
|
||||
try {
|
||||
value = await schema.validateAsync(req.body, { allowUnknown: true });
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR]", err);
|
||||
await axios.get("https://app.divera247.com/api/v2/alarms?accesskey=qX1RZwmThqB0mFDkd_Bx7CNja6eHvoSCRjyb4RyGBZ40afdai6lWXbH_1YvbB5Uy")
|
||||
.then((res) => {
|
||||
if (config.debug) {
|
||||
fs.writeFileSync(cacheFolder + "data.json", JSON.stringify(res.data))
|
||||
}
|
||||
console.log(res.data)
|
||||
value = res.data.data.items[res.data.data.sorting[0]]
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
if (config.activate_telegram) {
|
||||
sendMessage("[ERROR] Validation Error (Drucker Service): " + err, messageIDs)
|
||||
sendMessage("[ERROR] Divera data error(Drucker Service): " + error, messageIDs)
|
||||
}
|
||||
return res.status(403).send(err);
|
||||
return res.status(500).send(error);
|
||||
}
|
||||
if (value == {}) {
|
||||
if (config.activate_telegram) {
|
||||
sendMessage("[ERROR] No Value Data from Divera (Drucker Service): ", messageIDs)
|
||||
}
|
||||
return res.status(500).send("No Data");
|
||||
}
|
||||
|
||||
|
||||
|
||||
await main(value).catch(
|
||||
(err) => {
|
||||
|
||||
Reference in New Issue
Block a user