Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddbff495b3 | ||
|
|
b8fecd731c |
4
debug.js
4
debug.js
|
|
@ -16,9 +16,7 @@ ws.on('message', (data) => {
|
||||||
try {
|
try {
|
||||||
const msg = JSON.parse(data);
|
const msg = JSON.parse(data);
|
||||||
// Assuming the message has 'channel' and 'product_id' fields
|
// Assuming the message has 'channel' and 'product_id' fields
|
||||||
if (msg.channel && msg.product_data) {
|
console.log(`Channel: ${msg.data.fromChannel}, Product ID: ${msg.product_data}`);
|
||||||
console.log(`Channel: ${msg.channel}, Product ID: ${msg.product_data}`);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error parsing message:', err);
|
console.error('Error parsing message:', err);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
87
index.js
87
index.js
|
|
@ -457,31 +457,30 @@ xmpp.on("stanza", (stanza) => {
|
||||||
const bodyData = getFirstURL(body);
|
const bodyData = getFirstURL(body);
|
||||||
// get product id from "x" tag
|
// get product id from "x" tag
|
||||||
var evt = events[product_id.pil.substring(0, 3)];
|
var evt = events[product_id.pil.substring(0, 3)];
|
||||||
if (process.env.LOG_EVENTS === "true") {
|
|
||||||
// Log the full event object to a file named "productid-timestamp-channelname.json"
|
// Log the full event object to a file named "productid-timestamp-channelname.json"
|
||||||
const nowDate = new Date();
|
const nowDate = new Date();
|
||||||
const year = nowDate.getFullYear();
|
const year = nowDate.getFullYear();
|
||||||
const month = String(nowDate.getMonth() + 1).padStart(2, '0');
|
const month = String(nowDate.getMonth() + 1).padStart(2, '0');
|
||||||
const day = String(nowDate.getDate()).padStart(2, '0');
|
const day = String(nowDate.getDate()).padStart(2, '0');
|
||||||
const logDir = path.join(__dirname, "event-logs", year.toString(), month, day);
|
const logDir = path.join(__dirname, "event-logs", year.toString(), month, day);
|
||||||
if (!fs.existsSync(logDir)) {
|
if (!fs.existsSync(logDir)) {
|
||||||
fs.mkdirSync(logDir, { recursive: true });
|
fs.mkdirSync(logDir, { recursive: true });
|
||||||
}
|
|
||||||
const logFilename = `${product_id_raw}-${product_id.timestamp.toISOString()}-${fromChannel}.json`.replace(/[:]/g, "_");
|
|
||||||
const logPath = path.join(logDir, logFilename);
|
|
||||||
const getCircularReplacer = () => {
|
|
||||||
const seen = new WeakSet();
|
|
||||||
return (key, value) => {
|
|
||||||
if (typeof value === "object" && value !== null) {
|
|
||||||
if (seen.has(value)) {
|
|
||||||
return "WARN: CIRC";
|
|
||||||
}
|
|
||||||
seen.add(value);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
const logFilename = `${product_id_raw}-${product_id.timestamp.toISOString()}-${fromChannel}.json`.replace(/[:]/g, "_");
|
||||||
|
const logPath = path.join(logDir, logFilename);
|
||||||
|
const getCircularReplacer = () => {
|
||||||
|
const seen = new WeakSet();
|
||||||
|
return (key, value) => {
|
||||||
|
if (typeof value === "object" && value !== null) {
|
||||||
|
if (seen.has(value)) {
|
||||||
|
return "WARN: CIRC";
|
||||||
|
}
|
||||||
|
seen.add(value);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
if (!evt) {
|
if (!evt) {
|
||||||
evt = { name: "Unknown", priority: 3 }
|
evt = { name: "Unknown", priority: 3 }
|
||||||
|
|
@ -504,7 +503,7 @@ xmpp.on("stanza", (stanza) => {
|
||||||
const diff = (now - product_id.timestamp) / 1000 / 60;
|
const diff = (now - product_id.timestamp) / 1000 / 60;
|
||||||
if (diff > 3) return;
|
if (diff > 3) return;
|
||||||
// if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} New message from ${fromChannel}`);
|
// if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} New message from ${fromChannel}`);
|
||||||
console.log(`${colors.cyan("[INFO]")} ${fromChannel} ${getWFOByRoom(fromChannel).location} - ${product_id_raw} - ${evt.text} - ${product_id.timestamp}`);
|
console.log(`${colors.cyan("[INFO]")} ${getWFOByRoom(fromChannel).location} - ${product_id_raw} - ${evt.text} - ${product_id.timestamp}`);
|
||||||
messages++;
|
messages++;
|
||||||
textTries = 0;
|
textTries = 0;
|
||||||
tryGetText = () => {
|
tryGetText = () => {
|
||||||
|
|
@ -570,27 +569,25 @@ xmpp.on("stanza", (stanza) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
if (process.env.LOG_EVENTS === "true") {
|
fs.writeFileSync(logPath, JSON.stringify({
|
||||||
fs.writeFileSync(logPath, JSON.stringify({
|
evt, stanza, product_id, product_id_raw, bodyData, body, sentData: {
|
||||||
evt, stanza, product_id, product_id_raw, bodyData, body, sentData: {
|
"type": "iem-message",
|
||||||
"type": "iem-message",
|
"data": {
|
||||||
"data": {
|
"channel": getWFOByRoom(fromChannel),
|
||||||
"channel": getWFOByRoom(fromChannel),
|
"fromChannel": fromChannel,
|
||||||
"fromChannel": fromChannel,
|
"event": evt,
|
||||||
"event": evt,
|
"body": bodyData,
|
||||||
"body": bodyData,
|
"timestamp": product_id.timestamp,
|
||||||
"timestamp": product_id.timestamp,
|
"wmo": product_id.wmo,
|
||||||
"wmo": product_id.wmo,
|
"pil": product_id.pil,
|
||||||
"pil": product_id.pil,
|
"station": product_id.station,
|
||||||
"station": product_id.station,
|
"product_data": product_id,
|
||||||
"product_data": product_id,
|
"raw": product_id_raw,
|
||||||
"raw": product_id_raw,
|
"rawBody": body,
|
||||||
"rawBody": body,
|
"image": stanza.getChild("x").attrs.twitter_media || null
|
||||||
"image": stanza.getChild("x").attrs.twitter_media || null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, getCircularReplacer(), 2), 'utf8');
|
}
|
||||||
}
|
}, getCircularReplacer(), 2), 'utf8');
|
||||||
}
|
}
|
||||||
tryGetText();
|
tryGetText();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue