Gemessen am Live-Bestand: 8 von 125 Chat-Fotos trugen GPS-Koordinaten (5 im Rudel), obwohl die Rudel-Regeln „kein Standort“ versprechen; im Rudel-Chat gab es keinen Melden-Knopf, obwohl die Regeln „An jedem Beitrag … steht melden“ versprechen; eine Pause sperrte Bretter und Saal, aber nicht den Rudel-Chat; und es gab keine Mengen-Bremse. - helfer-bildmeta.mjs: entfernt EXIF/XMP/IPTC/Kommentare/Anhänge hinter dem Bildende aus JPEG, PNG, WebP Byte für Byte (kein Neukodieren), die Drehung bleibt. Nur im Crew-Haus (Zwei-Häuser-Regel). Ein Nachrüstlauf bereinigt die vorhandenen Crew-Fotos beim Start – vorher auf Kopien aller 22 Fotos mit Metadaten durchgespielt, Pillow bestätigt: Pixel gleich. - Melden im Rudel: eigene Tabelle chat_meldungen (treff_meldungen hängt per NOT NULL an Brettern), Momentaufnahme der Nachricht und der fünf davor, erscheint in derselben Liste „Meldungen & Maßnahmen“, eigener Weg zum Entscheiden, Push „rudel_meldung“ ans Team. Auskunft blendet die Momentaufnahme aus (Texte anderer Menschen), Aufbewahrung 180 Tage nach der Entscheidung. - chat-schutz.js: eine Stelle für Pause und Bremse (5 Nachrichten / 10 s, derselbe Text höchstens 3x, höchstens 5 @-Namen), gilt für Text, Foto und Bearbeiten; das Team ist ausgenommen. Das Eingabefeld sagt eine Pause vorher. - pruef-rudel-schutz.mjs: 71 Zusicherungen mit Gegenproben (Sabotage des Entferners und der Pause macht sie rot), Agentur bleibt Byte für Byte gleich. - mess-rudel-bilder.mjs: Bilder und Zielzahlen für die nächsten Stufen. Co-Authored-By: Claude Opus 5.5 <[email protected]>
239 lines
9.7 KiB
JavaScript
239 lines
9.7 KiB
JavaScript
/* =====================================================================
|
||
helfer-bildmeta.mjs — Metadaten aus Fotos entfernen (11.11.2026)
|
||
|
||
Gemessen am 11.11.2026 auf dem Server: 8 von 125 Chat-Fotos trugen
|
||
GPS-Koordinaten, 5 davon im Rudel. Wer so ein Foto herunterlaedt,
|
||
liest den Aufnahmeort aus -- oft die Wohnung. Die Rudel-Regeln
|
||
versprechen aber „Was gespeichert wird: … kein Standort".
|
||
|
||
---------------------------------------------------------------------
|
||
WARUM BYTEWEISE UND NICHT NEU KODIERT
|
||
|
||
Ein Neukodieren (Canvas, ffmpeg, eine Bildbibliothek) wuerde jedes
|
||
Foto ein zweites Mal verlustbehaftet speichern, Farben und Schaerfe
|
||
aendern und eine Abhaengigkeit ins Haus holen. Hier werden nur die
|
||
Kaesten herausgeschnitten, in denen Metadaten stehen; die Bilddaten
|
||
selbst bleiben Byte fuer Byte gleich.
|
||
|
||
DIE DREHUNG BLEIBT. Handys speichern ein hochkant gehaltenes Foto
|
||
oft quer und schreiben „um 90 Grad drehen" in die EXIF-Daten. Wer
|
||
EXIF ganz entfernt, stellt das Foto auf die Seite. Deshalb wird aus
|
||
dem alten Kasten nur der Wert „Orientation" gelesen und in einen
|
||
neuen, winzigen Kasten geschrieben, der NUR diesen Wert enthaelt.
|
||
|
||
---------------------------------------------------------------------
|
||
WAS ENTFERNT WIRD
|
||
|
||
JPEG APP1 (EXIF, XMP), APP13 (IPTC/Photoshop), COM, APP2-„MPF"
|
||
und alles nach dem Bildende (dort haengen Handys Zweitbilder
|
||
wie Tiefenkarten an, mit eigenen EXIF-Daten)
|
||
PNG eXIf, tEXt, zTXt, iTXt, tIME
|
||
WebP EXIF, „XMP " (und die passenden Merker im VP8X-Kopf)
|
||
GIF unveraendert -- GIF hat kein EXIF/GPS. Das sagt `ergebnis.art`.
|
||
|
||
Was bleibt: Farbprofil (ICC), JFIF, Bilddaten.
|
||
|
||
DREI AUSGAENGE (Hausregel vom 03.09.2026): `{ puffer, entfernt }` mit
|
||
Liste, `entfernt: []` wenn nichts drin war, und bei einer Datei, die
|
||
sich nicht sauber lesen laesst, `fehler` -- dann wird der ORIGINAL-
|
||
Puffer NICHT zurueckgegeben, sondern null. Ein Foto, das wir nicht
|
||
verstehen, wird nicht still mit Metadaten gespeichert.
|
||
===================================================================== */
|
||
|
||
const JPEG_SOI = 0xd8, JPEG_EOI = 0xd9, JPEG_SOS = 0xda;
|
||
|
||
/** Liest die EXIF-Drehung (1–8) aus einem APP1-Inhalt, sonst 0. */
|
||
function drehungAusExif(app1) {
|
||
try {
|
||
if (app1.length < 14 || app1.toString("latin1", 0, 6) !== "Exif\0\0") return 0;
|
||
const t = app1.subarray(6);
|
||
const klein = t.toString("latin1", 0, 2) === "II";
|
||
if (!klein && t.toString("latin1", 0, 2) !== "MM") return 0;
|
||
const u16 = (o) => (klein ? t.readUInt16LE(o) : t.readUInt16BE(o));
|
||
const u32 = (o) => (klein ? t.readUInt32LE(o) : t.readUInt32BE(o));
|
||
const ifd = u32(4);
|
||
if (ifd + 2 > t.length) return 0;
|
||
const n = u16(ifd);
|
||
for (let i = 0; i < n; i++) {
|
||
const e = ifd + 2 + i * 12;
|
||
if (e + 12 > t.length) return 0;
|
||
if (u16(e) === 0x0112) {
|
||
const w = u16(e + 8);
|
||
return w >= 1 && w <= 8 ? w : 0;
|
||
}
|
||
}
|
||
} catch { /* unlesbar = keine Drehung bekannt */ }
|
||
return 0;
|
||
}
|
||
|
||
/** Ein APP1-Kasten, der NUR die Drehung enthaelt (Big Endian). */
|
||
function drehungsKasten(wert) {
|
||
const inhalt = Buffer.alloc(6 + 8 + 2 + 12 + 4);
|
||
inhalt.write("Exif\0\0", 0, "latin1");
|
||
inhalt.write("MM", 6, "latin1");
|
||
inhalt.writeUInt16BE(42, 8);
|
||
inhalt.writeUInt32BE(8, 10); // erstes IFD direkt hinter dem Kopf
|
||
inhalt.writeUInt16BE(1, 14); // ein Eintrag
|
||
inhalt.writeUInt16BE(0x0112, 16); // Orientation
|
||
inhalt.writeUInt16BE(3, 18); // SHORT
|
||
inhalt.writeUInt32BE(1, 20); // Anzahl 1
|
||
inhalt.writeUInt16BE(wert, 24); // Wert, links ausgerichtet
|
||
inhalt.writeUInt32BE(0, 28); // kein weiteres IFD
|
||
const kopf = Buffer.from([0xff, 0xe1, 0, 0]);
|
||
kopf.writeUInt16BE(inhalt.length + 2, 2);
|
||
return Buffer.concat([kopf, inhalt]);
|
||
}
|
||
|
||
function jpeg(p) {
|
||
if (p[0] !== 0xff || p[1] !== JPEG_SOI) return { fehler: "kein JPEG-Anfang" };
|
||
const teile = [p.subarray(0, 2)];
|
||
const entfernt = [];
|
||
let drehung = 0;
|
||
let i = 2;
|
||
let nachJfif = 1; // wo der Drehungskasten hin soll (Index in teile)
|
||
while (i < p.length) {
|
||
if (p[i] !== 0xff) return { fehler: `Kasten erwartet bei ${i}` };
|
||
let m = p[i + 1];
|
||
while (m === 0xff) { i++; m = p[i + 1]; } // Fuellbytes
|
||
if (m === JPEG_EOI) { teile.push(p.subarray(i, i + 2)); i += 2; break; }
|
||
if (m >= 0xd0 && m <= 0xd7) { teile.push(p.subarray(i, i + 2)); i += 2; continue; }
|
||
if (i + 4 > p.length) return { fehler: "abgeschnitten" };
|
||
const laenge = p.readUInt16BE(i + 2);
|
||
if (laenge < 2 || i + 2 + laenge > p.length) return { fehler: "Kastenlaenge passt nicht" };
|
||
const kasten = p.subarray(i, i + 2 + laenge);
|
||
const inhalt = p.subarray(i + 4, i + 2 + laenge);
|
||
if (m === JPEG_SOS) {
|
||
/* Ab hier Bilddaten. Sie enthalten 0xFF nur als 0xFF00 oder als
|
||
Neustartmarke 0xFFD0–D7; das naechste andere 0xFFxx ist ein
|
||
echter Kasten (bei progressiven Bildern weitere DHT/SOS) oder
|
||
das Bildende. */
|
||
teile.push(kasten);
|
||
let j = i + 2 + laenge;
|
||
while (j < p.length - 1) {
|
||
if (p[j] === 0xff && p[j + 1] !== 0x00 && !(p[j + 1] >= 0xd0 && p[j + 1] <= 0xd7)) break;
|
||
j++;
|
||
}
|
||
teile.push(p.subarray(i + 2 + laenge, j));
|
||
i = j;
|
||
continue;
|
||
}
|
||
const kennung = inhalt.toString("latin1", 0, Math.min(inhalt.length, 12));
|
||
if (m === 0xe1) { // APP1: EXIF oder XMP
|
||
const d = drehungAusExif(inhalt);
|
||
if (d) drehung = d;
|
||
entfernt.push(kennung.startsWith("Exif") ? "EXIF" : "XMP");
|
||
} else if (m === 0xed) {
|
||
entfernt.push("IPTC");
|
||
} else if (m === 0xfe) {
|
||
entfernt.push("Kommentar");
|
||
} else if (m === 0xe2 && kennung.startsWith("MPF")) {
|
||
entfernt.push("MPF");
|
||
} else {
|
||
teile.push(kasten);
|
||
if (m === 0xe0 && kennung.startsWith("JFIF")) nachJfif = teile.length;
|
||
}
|
||
i += 2 + laenge;
|
||
}
|
||
if (i < p.length) entfernt.push(`Anhang hinter dem Bildende (${p.length - i} Byte)`);
|
||
if (!teile.length || teile[teile.length - 1][1] !== JPEG_EOI) {
|
||
return { fehler: "kein Bildende gefunden" };
|
||
}
|
||
if (drehung > 1) teile.splice(nachJfif, 0, drehungsKasten(drehung));
|
||
return { puffer: Buffer.concat(teile), entfernt, drehung: drehung || 1 };
|
||
}
|
||
|
||
const PNG_SIG = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
||
const PNG_WEG = new Set(["eXIf", "tEXt", "zTXt", "iTXt", "tIME"]);
|
||
|
||
function png(p) {
|
||
if (!p.subarray(0, 8).equals(PNG_SIG)) return { fehler: "kein PNG-Anfang" };
|
||
const teile = [PNG_SIG];
|
||
const entfernt = [];
|
||
let i = 8, ende = false;
|
||
while (i + 12 <= p.length) {
|
||
const laenge = p.readUInt32BE(i);
|
||
const typ = p.toString("latin1", i + 4, i + 8);
|
||
const stueck = p.subarray(i, i + 12 + laenge);
|
||
if (i + 12 + laenge > p.length) return { fehler: "Stueck abgeschnitten" };
|
||
if (PNG_WEG.has(typ)) entfernt.push(typ);
|
||
else teile.push(stueck);
|
||
i += 12 + laenge;
|
||
if (typ === "IEND") { ende = true; break; }
|
||
}
|
||
if (!ende) return { fehler: "kein IEND" };
|
||
if (i < p.length) entfernt.push(`Anhang hinter IEND (${p.length - i} Byte)`);
|
||
return { puffer: Buffer.concat(teile), entfernt, drehung: 1 };
|
||
}
|
||
|
||
function webp(p) {
|
||
if (p.toString("latin1", 0, 4) !== "RIFF" || p.toString("latin1", 8, 12) !== "WEBP") {
|
||
return { fehler: "kein WebP-Anfang" };
|
||
}
|
||
const teile = [];
|
||
const entfernt = [];
|
||
let vp8x = null;
|
||
let i = 12;
|
||
while (i + 8 <= p.length) {
|
||
const typ = p.toString("latin1", i, i + 4);
|
||
const laenge = p.readUInt32LE(i + 4);
|
||
const voll = 8 + laenge + (laenge & 1);
|
||
if (i + 8 + laenge > p.length) return { fehler: "Stueck abgeschnitten" };
|
||
const stueck = Buffer.from(p.subarray(i, Math.min(i + voll, p.length)));
|
||
if (typ === "EXIF" || typ === "XMP ") entfernt.push(typ.trim());
|
||
else {
|
||
if (typ === "VP8X") vp8x = stueck;
|
||
teile.push(stueck);
|
||
}
|
||
i += voll;
|
||
}
|
||
if (vp8x && vp8x.length >= 9) vp8x[8] &= ~(0x08 | 0x04); // EXIF- und XMP-Merker loeschen
|
||
const koerper = Buffer.concat(teile);
|
||
const kopf = Buffer.alloc(12);
|
||
kopf.write("RIFF", 0, "latin1");
|
||
kopf.writeUInt32LE(koerper.length + 4, 4);
|
||
kopf.write("WEBP", 8, "latin1");
|
||
return { puffer: Buffer.concat([kopf, koerper]), entfernt, drehung: 1 };
|
||
}
|
||
|
||
/**
|
||
* Entfernt Metadaten aus einem Foto.
|
||
* @param {Buffer} puffer
|
||
* @param {string} typ MIME-Typ, wie ihn dateiErkennen() bestimmt hat
|
||
* @returns {{puffer: Buffer|null, entfernt: string[], drehung?: number, fehler?: string, art: string}}
|
||
*/
|
||
export function bildMetaEntfernen(puffer, typ) {
|
||
const t = String(typ || "").toLowerCase();
|
||
let e;
|
||
try {
|
||
if (t === "image/jpeg") e = jpeg(puffer);
|
||
else if (t === "image/png") e = png(puffer);
|
||
else if (t === "image/webp") e = webp(puffer);
|
||
else return { puffer, entfernt: [], art: "unveraendert" };
|
||
} catch (f) {
|
||
e = { fehler: f?.message || "unlesbar" };
|
||
}
|
||
if (e.fehler) return { puffer: null, entfernt: [], fehler: e.fehler, art: "fehler" };
|
||
return { ...e, art: e.entfernt.length ? "bereinigt" : "sauber" };
|
||
}
|
||
|
||
/** Steht in diesem Foto noch ein GPS-Eintrag? (fuer Pruefungen und den
|
||
* Nachruestlauf -- liest nur, aendert nichts) */
|
||
export function hatGps(puffer) {
|
||
const s = puffer.toString("latin1");
|
||
let ab = 0;
|
||
for (;;) {
|
||
const at = s.indexOf("Exif\0\0", ab);
|
||
if (at < 0) return false;
|
||
const t = puffer.subarray(at + 6);
|
||
try {
|
||
const klein = t.toString("latin1", 0, 2) === "II";
|
||
const u16 = (o) => (klein ? t.readUInt16LE(o) : t.readUInt16BE(o));
|
||
const u32 = (o) => (klein ? t.readUInt32LE(o) : t.readUInt32BE(o));
|
||
const ifd = u32(4);
|
||
const n = u16(ifd);
|
||
for (let i = 0; i < n; i++) if (u16(ifd + 2 + i * 12) === 0x8825) return true;
|
||
} catch { /* weitersuchen */ }
|
||
ab = at + 6;
|
||
}
|
||
}
|