V 1.2.1 source-Feld im POST-Body (loop/archive)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -30,11 +30,11 @@ function log(msg) { console.log (`[${fmt24h(new Date())}] ${msg}`); }
|
|||||||
function warn(msg) { console.warn(`[${fmt24h(new Date())}] WARN ${msg}`); }
|
function warn(msg) { console.warn(`[${fmt24h(new Date())}] WARN ${msg}`); }
|
||||||
function err(msg) { console.error(`[${fmt24h(new Date())}] ERROR ${msg}`); }
|
function err(msg) { console.error(`[${fmt24h(new Date())}] ERROR ${msg}`); }
|
||||||
|
|
||||||
function postData(data) {
|
function postData(data, source) {
|
||||||
if (!POST_URL) return;
|
if (!POST_URL) return;
|
||||||
const headers = { "Content-Type": "application/json" };
|
const headers = { "Content-Type": "application/json" };
|
||||||
if (COLLECTOR_API_KEY) headers["X-API-Key"] = COLLECTOR_API_KEY;
|
if (COLLECTOR_API_KEY) headers["X-API-Key"] = COLLECTOR_API_KEY;
|
||||||
fetch(POST_URL, { method: "POST", headers, body: JSON.stringify(data) })
|
fetch(POST_URL, { method: "POST", headers, body: JSON.stringify({ ...data, source }) })
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const text = await res.text().catch(() => "");
|
const text = await res.text().catch(() => "");
|
||||||
@@ -106,7 +106,7 @@ async function catchUpArchive(db) {
|
|||||||
const inserted = insertRecords(db, records, "archive");
|
const inserted = insertRecords(db, records, "archive");
|
||||||
log(`Archiv: ${inserted} neue Datensätze gespeichert (${records.length} empfangen).`);
|
log(`Archiv: ${inserted} neue Datensätze gespeichert (${records.length} empfangen).`);
|
||||||
|
|
||||||
for (const r of records) postData(r);
|
for (const r of records) postData(r, "archive");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── LOOP-Schleife ──────────────────────────────────────────────────────────
|
// ── LOOP-Schleife ──────────────────────────────────────────────────────────
|
||||||
@@ -126,7 +126,7 @@ async function runLoop(db) {
|
|||||||
const data = await fetchLoopData(station);
|
const data = await fetchLoopData(station);
|
||||||
buffer.push(data);
|
buffer.push(data);
|
||||||
|
|
||||||
postData(data);
|
postData(data, "loop");
|
||||||
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (now - lastDbWrite >= DB_INTERVAL_MS) {
|
if (now - lastDbWrite >= DB_INTERVAL_MS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user