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:
2026-05-19 10:21:19 +02:00
parent 842727a851
commit 4798e5f9c9
+4 -4
View File
@@ -30,11 +30,11 @@ function log(msg) { console.log (`[${fmt24h(new Date())}] ${msg}`); }
function warn(msg) { console.warn(`[${fmt24h(new Date())}] WARN ${msg}`); }
function err(msg) { console.error(`[${fmt24h(new Date())}] ERROR ${msg}`); }
function postData(data) {
function postData(data, source) {
if (!POST_URL) return;
const headers = { "Content-Type": "application/json" };
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 => {
if (!res.ok) {
const text = await res.text().catch(() => "");
@@ -106,7 +106,7 @@ async function catchUpArchive(db) {
const inserted = insertRecords(db, records, "archive");
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 ──────────────────────────────────────────────────────────
@@ -126,7 +126,7 @@ async function runLoop(db) {
const data = await fetchLoopData(station);
buffer.push(data);
postData(data);
postData(data, "loop");
const now = Date.now();
if (now - lastDbWrite >= DB_INTERVAL_MS) {