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",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"main": "src/index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
@@ -20,4 +20,4 @@
|
||||
"pdf-to-printer": "^5.6.0",
|
||||
"puppeteer": "^19.9.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,53 +8,52 @@ import path, { join } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
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
|
||||
const token = '6150769224:AAGhBagPEi23QtBJl65YNuwEBBXwHguDV0E';
|
||||
if (config.activate_telegram) {
|
||||
const token = '6150769224:AAGhBagPEi23QtBJl65YNuwEBBXwHguDV0E';
|
||||
|
||||
const messageIDs = [1034133487]
|
||||
const messageIDs = [1034133487]
|
||||
|
||||
// Create a bot that uses 'polling' to fetch new updates
|
||||
const bot = new TelegramBot(token, { polling: true });
|
||||
// Create a bot that uses 'polling' to fetch new updates
|
||||
const bot = new TelegramBot(token, { polling: true });
|
||||
|
||||
bot.setMyCommands([
|
||||
{ command: '/chatid', description: 'Zeigt deine Chat ID' },
|
||||
{ command: '/druckerliste', description: 'Zeigt alle Drucker' },
|
||||
])
|
||||
bot.setMyCommands([
|
||||
{ command: '/chatid', description: 'Zeigt deine Chat ID' },
|
||||
{ command: '/druckerliste', description: 'Zeigt alle Drucker' },
|
||||
])
|
||||
|
||||
bot.on('message', async (msg) => {
|
||||
const chatId = msg.chat.id;
|
||||
bot.on('message', async (msg) => {
|
||||
const chatId = msg.chat.id;
|
||||
|
||||
switch (msg.text) {
|
||||
case '/chatid':
|
||||
bot.sendMessage(chatId, 'Deine Chat ID ist: ' + chatId);
|
||||
break;
|
||||
case '/druckerliste':
|
||||
let message = ""
|
||||
switch (msg.text) {
|
||||
case '/chatid':
|
||||
bot.sendMessage(chatId, 'Deine Chat ID ist: ' + chatId);
|
||||
break;
|
||||
case '/druckerliste':
|
||||
let message = ""
|
||||
|
||||
const printers = await pdfLib.getPrinters()
|
||||
printers.forEach((printer) => {
|
||||
message += printer.deviceId + "\n"
|
||||
});
|
||||
const printers = await pdfLib.getPrinters()
|
||||
printers.forEach((printer) => {
|
||||
message += printer.deviceId + "\n"
|
||||
});
|
||||
|
||||
bot.sendMessage(chatId, 'Drucker Liste:\n' + message);
|
||||
default:
|
||||
bot.sendMessage(chatId, 'Drucker Liste:\n' + message);
|
||||
default:
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
function sendMessage(msg, idList) {
|
||||
idList.forEach((id) => {
|
||||
bot.sendMessage(id, msg);
|
||||
})
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
function sendMessage(msg, idList) {
|
||||
idList.forEach((id) => {
|
||||
bot.sendMessage(id, msg);
|
||||
})
|
||||
sendMessage("[INFO]: Drucker Service wird gestartet", messageIDs)
|
||||
}
|
||||
|
||||
// setInterval(() => {
|
||||
// messageIDs.forEach((id) => {
|
||||
// bot.set(id, new Date().toLocaleString());
|
||||
// })
|
||||
// }, 3 * 60 * 1000)
|
||||
|
||||
sendMessage("[INFO]: Drucker Service wird gestartet", messageIDs)
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
|
||||
@@ -73,8 +72,7 @@ const schema = Joi.object({
|
||||
|
||||
var Logo = fs.readFileSync("./assets/Logo_fwaur.png", { encoding: "latin1" });
|
||||
|
||||
const printerName = "Microsoft Print to PDF"
|
||||
// const printerName = "OKI-MC853-CE9408"
|
||||
const printerName = config.printer_device_id;
|
||||
const cacheFolder = "./cache/"
|
||||
|
||||
const app = express();
|
||||
@@ -89,7 +87,9 @@ app.post('/', async (req, res) => {
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR]", err);
|
||||
sendMessage("[ERROR] Validation Error (Drucker Service): " + err, messageIDs)
|
||||
if (config.activate_telegram) {
|
||||
sendMessage("[ERROR] Validation Error (Drucker Service): " + err, messageIDs)
|
||||
}
|
||||
return res.status(403).send(err);
|
||||
}
|
||||
|
||||
@@ -97,8 +97,9 @@ app.post('/', async (req, res) => {
|
||||
await main(value).catch(
|
||||
(err) => {
|
||||
console.log(err);
|
||||
sendMessage("[ERROR] Internal Server Error (Drucker Service): " + err, messageIDs)
|
||||
|
||||
if (config.activate_telegram) {
|
||||
sendMessage("[ERROR] Internal Server Error (Drucker Service): " + err, messageIDs)
|
||||
}
|
||||
return res.status(500).send(err);
|
||||
}
|
||||
);
|
||||
@@ -1668,7 +1669,7 @@ async function createPDF(_alarmData) {
|
||||
|
||||
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);
|
||||
|
||||
@@ -1690,7 +1691,7 @@ async function puppeteerGetImage(lat, lng) {
|
||||
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>`;
|
||||
})
|
||||
await page.screenshot({ path: './cache/map.png' });
|
||||
await page.screenshot({ path: cacheFolder + 'map.png' });
|
||||
|
||||
await browser.close();
|
||||
return;
|
||||
@@ -1712,6 +1713,4 @@ async function main(data = testData) {
|
||||
|
||||
app.listen(2000, () => {
|
||||
console.log(`PDF Printing Service listening on port 2000`);
|
||||
})
|
||||
|
||||
// main()
|
||||
})
|
||||
Reference in New Issue
Block a user