pruef-galerie und pruef-support-bilder beantworten seit heute, OB sich die Bildschau oeffnet -- mit Gegenprobe. Keine von beiden kann sagen, ob sie gut aussieht; ein Haken ist kein Bild. Vier Lagen, weil die Schau sich nach dem FOTO richtet und nicht nach dem Bildschirm (bildschau.js, lageBestimmen): quer am Rechner -> "DogFather" oben und "Team Dogi" unten, hoch am Rechner -> Husky und Hase daneben, am Handy -> nur das Foto, weil daneben kein Platz ist. Gemessen: quer/hoch/keine/quer -- genau so gewollt. Die Testfotos werden gemalt (helfer-png-bauen) statt mitgeliefert: ein Bild im Repo altert, eine Rechenvorschrift nicht. Und sie sind echte PNG mit Struktur, keine 1x1-Punkte -- ueber Anordnung sagt ein Punkt nichts. Co-Authored-By: Claude Opus 5 <[email protected]>
196 lines
8.5 KiB
JavaScript
196 lines
8.5 KiB
JavaScript
/* =====================================================================
|
|
WIE SIEHT EIN FOTO AUS, WENN MAN ES AUFMACHT? (11.10.2026)
|
|
=====================================================================
|
|
|
|
Filipe: „auf der crew seite wenn ich fotos auf mache sieht das immer
|
|
noch so aus wie auf dem screen. ich will aber dass es dan aussieht
|
|
wie bei der workspace seite."
|
|
|
|
Die Pruefungen daneben beantworten, OB sich die Bildschau oeffnet
|
|
(pruef-galerie, pruef-support-bilder -- beide mit Gegenprobe). Sie
|
|
koennen nicht beantworten, ob sie gut aussieht. Dafuer gibt es diese
|
|
Datei: Sie macht Bilder, keine Haken.
|
|
|
|
VIER LAGEN, WEIL DIE SCHAU SICH NACH DEM FOTO RICHTET und nicht nach
|
|
dem Bildschirm (siehe bildschau.js, `lageBestimmen`):
|
|
|
|
* quer am Rechner -> „DogFather" oben, „Team Dogi" unten
|
|
* hoch am Rechner -> Husky links, Hase rechts
|
|
* am Handy -> nur das Foto. Dort IST kein Platz daneben,
|
|
und eine Figur ueber dem Bild waere keine
|
|
Zierde, sondern ein Hindernis.
|
|
|
|
DIE TESTFOTOS SIND ECHTE PNG und keine 1x1-Punkte: Ein Punkt sagt
|
|
ueber Anordnung nichts. Sie werden hier gemalt statt mitgeliefert --
|
|
ein Bild im Repo altert, eine Rechenvorschrift nicht.
|
|
|
|
Aufrufen mit: node server/mess-fotoschau.mjs
|
|
Die Bilder landen als server/mess-fotoschau-*.png.
|
|
===================================================================== */
|
|
import { mkdtempSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
import { eigenerPort } from "./helfer-port.mjs";
|
|
import { notbremse } from "./helfer-notbremse.mjs";
|
|
import { pngBauen } from "./helfer-png-bauen.mjs";
|
|
import { heuteLokal } from "./helfer-tag.mjs";
|
|
|
|
const PORT = await eigenerPort(import.meta, "mess-fotoschau");
|
|
const ordner = mkdtempSync(join(tmpdir(), "ws-fotoschau-"));
|
|
process.env.WORKSPACE_DB = join(ordner, "workspace.db");
|
|
process.env.WORKSPACE_DATEN = join(ordner, "daten");
|
|
process.env.PORT = String(PORT);
|
|
process.env.SITE_ACCESS_SECRET = "lokaler-test";
|
|
process.env.SITE_ACCESS_CODE_DOGI = "DOGI-TEST-1";
|
|
process.env.SITE_PUBLIC_LAUNCH_AT = "2020-01-01T00:00:00+01:00";
|
|
|
|
const express = (await import("express")).default;
|
|
const ec = express.response.cookie;
|
|
express.response.cookie = function (n, w, o) {
|
|
return ec.call(this, n, w, { ...(o || {}), secure: false });
|
|
};
|
|
await import("./index.js");
|
|
notbremse(240_000, "mess-fotoschau");
|
|
await new Promise((r) => setTimeout(r, 800));
|
|
const BASIS = `http://127.0.0.1:${PORT}`;
|
|
|
|
/* ---- ein Zugang ---------------------------------------------------- */
|
|
const { DatabaseSync } = await import("node:sqlite");
|
|
const { scryptSync, randomBytes, createHmac } = await import("node:crypto");
|
|
const d = new DatabaseSync(process.env.WORKSPACE_DB);
|
|
const jetzt = new Date().toISOString();
|
|
const schluessel = randomBytes(32).toString("hex");
|
|
d.prepare("INSERT INTO einstellungen (schluessel, wert, geaendert, von)"
|
|
+ " VALUES (?,?,?,NULL) ON CONFLICT(schluessel) DO NOTHING")
|
|
.run("code_kennung_schluessel", schluessel, jetzt);
|
|
const salz = randomBytes(16).toString("hex");
|
|
const hash = scryptSync("CODE-DOGI-0001", salz, 64,
|
|
{ N: 32768, r: 8, p: 1, maxmem: 96 * 1024 * 1024 }).toString("hex");
|
|
d.prepare("INSERT INTO personen"
|
|
+ " (name, rolle, code_hash, code_salt, code_n, code_kennung, aktiv, erstellt)"
|
|
+ " VALUES (?,?,?,?,?,?,1,?)")
|
|
.run("Filipe", "admin", hash, salz, 32768,
|
|
createHmac("sha256", schluessel).update("CODE-DOGI-0001").digest("hex"), jetzt);
|
|
d.close();
|
|
|
|
const an = await fetch(BASIS + "/workspace/api/anmelden", {
|
|
method: "POST", headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ rolle: "admin", code: "CODE-DOGI-0001" }),
|
|
});
|
|
const dogi = (an.headers.getSetCookie?.() || []).map((z) => z.split(";")[0]).join("; ");
|
|
|
|
/* ---- zwei Beitraege, je ein Foto ------------------------------------
|
|
GETRENNT, NICHT ZWEI AN EINEM BEITRAG: Im Bildstreifen stehen
|
|
mehrere Fotos nebeneinander und werden dabei schmaler -- dann saehe
|
|
man auf dem Bildschirmfoto die Kachel und nicht die Schau. */
|
|
async function beitragMitFoto(titel, breit, hoch, male) {
|
|
const a = await fetch(BASIS + "/workspace/api/bereich/highlight", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json", cookie: dogi, origin: BASIS },
|
|
body: JSON.stringify({ art: "clip", titel, datum: heuteLokal() }),
|
|
});
|
|
const id = (await a.json().catch(() => null))?.id || 0;
|
|
await fetch(BASIS + "/workspace/api/dateien", {
|
|
method: "POST",
|
|
headers: {
|
|
cookie: dogi, origin: BASIS, "content-type": "image/png",
|
|
"x-dateiname": encodeURIComponent(
|
|
titel.toLowerCase().replace(/[^a-z0-9]+/g, "-") + ".png"),
|
|
"x-eintrag": String(id),
|
|
},
|
|
body: pngBauen(breit, hoch, male),
|
|
});
|
|
return id;
|
|
}
|
|
|
|
/* Ein Verlauf mit zwei hellen Formen darin -- genug Struktur, um zu
|
|
sehen, ob das Bild gestaucht oder beschnitten wird. */
|
|
const motiv = (x, y, b, h) => {
|
|
const fx = x / b, fy = y / h;
|
|
if (Math.hypot(fx - 0.5, fy - 0.42) < 0.17) return [250, 214, 128];
|
|
if (fy > 0.76 && fy < 0.86 && fx > 0.18 && fx < 0.82) return [126, 214, 233];
|
|
return [
|
|
Math.round(18 + 52 * fx),
|
|
Math.round(24 + 44 * fy),
|
|
Math.round(48 + 86 * (1 - fy)),
|
|
];
|
|
};
|
|
|
|
await beitragMitFoto("Querformat vom Live", 1280, 720, motiv);
|
|
await beitragMitFoto("Hochformat vom Handy", 900, 1600, motiv);
|
|
|
|
/* ---- Browser, oder der dritte Ausgang -------------------------------- */
|
|
let pw = null;
|
|
try {
|
|
pw = await import(
|
|
"file:///C:/Users/qciga/Documents/Obelix/Analyse/node_modules/playwright/index.mjs");
|
|
} catch (f) {
|
|
console.log("KONNTE NICHT NACHSEHEN: Playwright fehlt (" + (f?.message || "") + ").");
|
|
console.log(" Nachinstallieren in C:/Users/qciga/Documents/Obelix/Analyse:");
|
|
console.log(" npm i -D playwright");
|
|
try { rmSync(ordner, { recursive: true, force: true }); } catch { /* egal */ }
|
|
process.exit(2);
|
|
}
|
|
const browser = await pw.chromium.launch();
|
|
|
|
/** Ein Foto aufmachen und fotografieren.
|
|
*
|
|
* Der Beitrag wird ueber seinen TITEL gesucht, nicht ueber die
|
|
* Reihenfolge: Die kann sich aendern, der Titel nicht.
|
|
*/
|
|
async function schauFoto(name, breit, hoch, titel) {
|
|
const kontext = await browser.newContext({
|
|
viewport: { width: breit, height: hoch },
|
|
deviceScaleFactor: 2, hasTouch: breit <= 860,
|
|
});
|
|
await kontext.addCookies(dogi.split("; ").map((k) => {
|
|
const [n, ...r] = k.split("=");
|
|
return { name: n, value: r.join("="), domain: "127.0.0.1", path: "/" };
|
|
}));
|
|
const seite = await kontext.newPage();
|
|
await seite.goto(`${BASIS}/workspace/bereich.html?b=highlight`, { waitUntil: "networkidle" });
|
|
await seite.waitForSelector(".bildstreifen__bild", { timeout: 15000 });
|
|
await seite.waitForTimeout(500);
|
|
|
|
const feld = seite.locator(".eintrag-karte", { hasText: titel })
|
|
.locator(".bildstreifen__feld").first();
|
|
await feld.click();
|
|
await seite.waitForSelector("dialog.bildschau[open]", { timeout: 8000 });
|
|
|
|
/* Die Begleiter blenden sich mit .32s ein. Eine feste Wartezeit waere
|
|
geraten; gewartet wird, bis die Deckung wirklich steht. Unter Last
|
|
ist `requestAnimationFrame` gedrosselt und eine Blende kann
|
|
stillstehen -- deshalb eine Frist und kein ewiges Warten. */
|
|
await seite.waitForFunction(() => {
|
|
const f = [...document.querySelectorAll(".bildschau__figur, .bildschau__wort")];
|
|
if (!f.length) return true;
|
|
return f.every((e) => {
|
|
const deckung = Number(getComputedStyle(e).opacity);
|
|
return deckung === 0 || deckung > 0.95;
|
|
});
|
|
}, null, { timeout: 5000 }).catch(() => { /* dann eben so, wie es steht */ });
|
|
await seite.waitForTimeout(250);
|
|
|
|
const lage = await seite.evaluate(() =>
|
|
document.querySelector("dialog.bildschau[open]")?.dataset.lage || "?");
|
|
const pfad = fileURLToPath(new URL(name, import.meta.url));
|
|
await seite.screenshot({ path: pfad });
|
|
console.log(` ${name} (${breit}x${hoch}, Lage „${lage}")`);
|
|
await kontext.close();
|
|
}
|
|
|
|
console.log("");
|
|
console.log("=== Ein Foto aufmachen ===");
|
|
await schauFoto("mess-fotoschau-rechner-quer.png", 1440, 900, "Querformat vom Live");
|
|
await schauFoto("mess-fotoschau-rechner-hoch.png", 1440, 900, "Hochformat vom Handy");
|
|
await schauFoto("mess-fotoschau-handy-hoch.png", 412, 915, "Hochformat vom Handy");
|
|
await schauFoto("mess-fotoschau-handy-quer.png", 412, 915, "Querformat vom Live");
|
|
|
|
await browser.close();
|
|
console.log("");
|
|
console.log("Fertig. Die Bilder liegen in server/.");
|
|
try { rmSync(ordner, { recursive: true, force: true }); } catch { /* Aufraeumrest */ }
|
|
process.exit(0);
|