/* Macht ein Bild der fertigen Kachel -- zum Ansehen, nicht zum Pruefen. Die Pruefung dazu ist pruef-tagesblick.mjs. */ import { mkdtempSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; const ordner = mkdtempSync(join(tmpdir(), "ws-bild-")); process.env.WORKSPACE_DB = join(ordner, "workspace.db"); const { portMussFreiSein } = await import("./helfer-port.mjs"); /* DIE ANTWORT DES WAECHTERS WIRD BENUTZT (01.10.2026). Hier stand die Zahl dreimal, und der Rueckgabewert wurde weggeworfen. Gibt das System den Port dauerhaft nicht her, weicht `portMussFreiSein` auf Port + 4000 aus und meldet die neue Nummer -- dieses Werkzeug lauschte danach trotzdem auf der alten und stuerzte mit `listen EACCES` ab. Genau der Fall ist am 23.09. auf Port 5040 eingetreten. */ const PORT = await portMussFreiSein(4307, "das Bildwerkzeug"); process.env.PORT = String(PORT); process.env.SITE_ACCESS_SECRET = "lokaler-test"; 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"); await new Promise((r) => setTimeout(r, 900)); const BASIS = `http://127.0.0.1:${PORT}`; const { DatabaseSync } = await import("node:sqlite"); const { scryptSync, randomBytes } = await import("node:crypto"); await fetch(BASIS + "/workspace/api/anmelden", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ rolle: "admin", code: "x" }) }).catch(() => {}); for (let i = 0; i < 60; i++) { try { const p = new DatabaseSync(process.env.WORKSPACE_DB); try { p.prepare("SELECT 1 FROM personen LIMIT 1").get(); break; } finally { p.close(); } } catch { await new Promise((r) => setTimeout(r, 250)); } } const d = new DatabaseSync(process.env.WORKSPACE_DB); const jetztIso = new Date().toISOString(); function anlegen(name, rolle, code) { const salt = randomBytes(16).toString("hex"); const hash = scryptSync(code, salt, 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, aktiv, erstellt) VALUES (?,?,?,?,?,1,?)") .run(name, rolle, hash, salt, 32768, jetztIso); return d.prepare("SELECT last_insert_rowid() AS id").get().id; } const idDogi = anlegen("Filipe", "admin", "CODE-DOGI-0001"); const idScout = anlegen("Patrick von Hohenstein", "scout", "CODE-SCOU-0001"); const idLuna = anlegen("Luna", "creator", "CODE-CREA-0001"); const idNora = anlegen("Nora", "creator", "CODE-CREA-0002"); d.prepare("INSERT INTO betreuung (creator_id, betreuer_id, seit) VALUES (?,?,?)").run(idLuna, idScout, jetztIso); d.prepare("INSERT INTO betreuung (creator_id, betreuer_id, seit) VALUES (?,?,?)").run(idNora, idScout, jetztIso); const n = new Date(); const HEUTE = `${n.getFullYear()}-${String(n.getMonth() + 1).padStart(2, "0")}-${String(n.getDate()).padStart(2, "0")}`; /* Rund um die aktuelle Uhrzeit, damit das Bild alle drei Zustaende zeigt: vorbei, als Naechstes dran, spaeter. */ const stunde = n.getHours(); const zeit = (h) => `${String(Math.max(0, Math.min(23, h))).padStart(2, "0")}:00`; function termin(titel, h, art, dauer, wer) { d.prepare(`INSERT INTO termine (titel, art, beginn, dauer_min, creator_id, teilnehmer_id, ort, erstellt, erstellt_von) VALUES (?,?,?,?,?,?,?,?,?)`) .run(titel, art, `${HEUTE}T${zeit(h)}`, dauer, wer, wer, null, jetztIso, idDogi); } termin("Wochen-Call mit Luna", stunde - 3, "call", 30, idLuna); termin("Content-Freigabe Nora", stunde - 1, "review", 45, idNora); termin("Strategie mit Patrick", stunde + 1, "termin", 60, idLuna); termin("Abschluss-Call", stunde + 3, "call", 30, idNora); d.prepare(`INSERT INTO aufgaben (titel, status, prioritaet, frist, creator_id, verantwortlich_id, erstellt, erstellt_von) VALUES (?,?,'hoch',?,?,?,?,?)`) .run("Thumbnails prüfen", "offen", "2020-01-01", idLuna, idLuna, jetztIso, idDogi); d.prepare(`INSERT INTO aufgaben (titel, status, prioritaet, frist, creator_id, verantwortlich_id, erstellt, erstellt_von) VALUES (?,?,'hoch',?,?,?,?,?)`) .run("Review Freigabe", "review", HEUTE, idNora, idNora, jetztIso, idDogi); d.close(); const pw = await import("file:///C:/Users/qciga/Documents/Obelix/Analyse/node_modules/playwright/index.mjs"); const browser = await pw.chromium.launch(); for (const [breite, name] of [[1280, "computer"], [390, "handy"]]) { const ctx = await browser.newContext({ viewport: { width: breite, height: 1000 }, deviceScaleFactor: 2, }); const seite = await ctx.newPage(); await seite.goto(BASIS + "/workspace/", { waitUntil: "networkidle" }); await seite.click('.rolle[data-rolle="admin"]'); await seite.fill("#code", "CODE-DOGI-0001"); await seite.click("button[type=submit]"); await seite.waitForURL("**/start.html", { timeout: 25000 }); await seite.waitForTimeout(1400); const kachel = await seite.$("#dran-block"); if (kachel) { await kachel.screenshot({ path: `tagesblick-${name}.png` }); console.log(`tagesblick-${name}.png geschrieben`); } else { console.log(`${name}: Kachel nicht gefunden`); } await ctx.close(); } await browser.close(); try { rmSync(ordner, { recursive: true, force: true }); } catch { /* egal */ } process.exit(0);