feat(root) config.json
This commit is contained in:
4
config.json
Normal file
4
config.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"activate_telegram": false,
|
||||||
|
"printer_device_id": "Microsoft Print to PDF"
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "printer_service",
|
"name": "printer_service",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "src/index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ import path, { join } from 'path';
|
|||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import TelegramBot from 'node-telegram-bot-api';
|
import TelegramBot from 'node-telegram-bot-api';
|
||||||
|
|
||||||
|
const config = JSON.parse(fs.readFileSync("./config.json", "utf8"));
|
||||||
|
|
||||||
// replace the value below with the Telegram token you receive from @BotFather
|
// replace the value below with the Telegram token you receive from @BotFather
|
||||||
|
if (config.activate_telegram) {
|
||||||
const token = '6150769224:AAGhBagPEi23QtBJl65YNuwEBBXwHguDV0E';
|
const token = '6150769224:AAGhBagPEi23QtBJl65YNuwEBBXwHguDV0E';
|
||||||
|
|
||||||
const messageIDs = [1034133487]
|
const messageIDs = [1034133487]
|
||||||
@@ -48,13 +51,9 @@ function sendMessage(msg, idList) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// setInterval(() => {
|
|
||||||
// messageIDs.forEach((id) => {
|
|
||||||
// bot.set(id, new Date().toLocaleString());
|
|
||||||
// })
|
|
||||||
// }, 3 * 60 * 1000)
|
|
||||||
|
|
||||||
sendMessage("[INFO]: Drucker Service wird gestartet", messageIDs)
|
sendMessage("[INFO]: Drucker Service wird gestartet", messageIDs)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
|
||||||
@@ -73,8 +72,7 @@ const schema = Joi.object({
|
|||||||
|
|
||||||
var Logo = fs.readFileSync("./assets/Logo_fwaur.png", { encoding: "latin1" });
|
var Logo = fs.readFileSync("./assets/Logo_fwaur.png", { encoding: "latin1" });
|
||||||
|
|
||||||
const printerName = "Microsoft Print to PDF"
|
const printerName = config.printer_device_id;
|
||||||
// const printerName = "OKI-MC853-CE9408"
|
|
||||||
const cacheFolder = "./cache/"
|
const cacheFolder = "./cache/"
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -89,7 +87,9 @@ app.post('/', async (req, res) => {
|
|||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.log("[ERROR]", err);
|
console.log("[ERROR]", err);
|
||||||
|
if (config.activate_telegram) {
|
||||||
sendMessage("[ERROR] Validation Error (Drucker Service): " + err, messageIDs)
|
sendMessage("[ERROR] Validation Error (Drucker Service): " + err, messageIDs)
|
||||||
|
}
|
||||||
return res.status(403).send(err);
|
return res.status(403).send(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,8 +97,9 @@ app.post('/', async (req, res) => {
|
|||||||
await main(value).catch(
|
await main(value).catch(
|
||||||
(err) => {
|
(err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
if (config.activate_telegram) {
|
||||||
sendMessage("[ERROR] Internal Server Error (Drucker Service): " + err, messageIDs)
|
sendMessage("[ERROR] Internal Server Error (Drucker Service): " + err, messageIDs)
|
||||||
|
}
|
||||||
return res.status(500).send(err);
|
return res.status(500).send(err);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -1668,7 +1669,7 @@ async function createPDF(_alarmData) {
|
|||||||
|
|
||||||
await puppeteerGetImage(_alarmData.lat, _alarmData.lng)
|
await puppeteerGetImage(_alarmData.lat, _alarmData.lng)
|
||||||
|
|
||||||
const mapImg = fs.readFileSync("./cache/map.png", "base64")
|
const mapImg = fs.readFileSync(cacheFolder + "map.png", "base64")
|
||||||
|
|
||||||
doc.addImage(mapImg, 10, 25);
|
doc.addImage(mapImg, 10, 25);
|
||||||
|
|
||||||
@@ -1690,7 +1691,7 @@ async function puppeteerGetImage(lat, lng) {
|
|||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
document.body.innerHTML += `<div id="centerPoint" style="height: 15px;width: 15px;border-radius: 50%;background-color: red;position: absolute;border: 3px solid green;margin: auto;top: 0;bottom: 0;left: 0;right: 0;z-index: 100;"></div><style>#OpenLayers_Control_PanZoomBar_3, #OpenLayers_Control_LayerSwitcher_4, nam1, nam2, dasch, #OpenLayers_Control_Attribution_9, #OpenLayers_Control_Permalink_7, #OpenLayers_Control_Permalink_5 {display:none !important;} </style>`;
|
document.body.innerHTML += `<div id="centerPoint" style="height: 15px;width: 15px;border-radius: 50%;background-color: red;position: absolute;border: 3px solid green;margin: auto;top: 0;bottom: 0;left: 0;right: 0;z-index: 100;"></div><style>#OpenLayers_Control_PanZoomBar_3, #OpenLayers_Control_LayerSwitcher_4, nam1, nam2, dasch, #OpenLayers_Control_Attribution_9, #OpenLayers_Control_Permalink_7, #OpenLayers_Control_Permalink_5 {display:none !important;} </style>`;
|
||||||
})
|
})
|
||||||
await page.screenshot({ path: './cache/map.png' });
|
await page.screenshot({ path: cacheFolder + 'map.png' });
|
||||||
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
return;
|
return;
|
||||||
@@ -1713,5 +1714,3 @@ async function main(data = testData) {
|
|||||||
app.listen(2000, () => {
|
app.listen(2000, () => {
|
||||||
console.log(`PDF Printing Service listening on port 2000`);
|
console.log(`PDF Printing Service listening on port 2000`);
|
||||||
})
|
})
|
||||||
|
|
||||||
// main()
|
|
||||||
Reference in New Issue
Block a user