Kalender-Abos Baustellen und Aufgaben für Outlook classic, Caddy lässt /kalender ohne Anmeldung durch
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
This commit is contained in:
@@ -3,10 +3,12 @@ import fastifyStatic from "@fastify/static";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
import { existsSync } from "node:fs";
|
||||
import { randomBytes, timingSafeEqual } from "node:crypto";
|
||||
import { z, ZodError } from "zod";
|
||||
import { type Client, type Pool, transaktion } from "./db.js";
|
||||
import { mitNeuplanung, pruefeVerknuepfung, terminplan } from "./terminplan.js";
|
||||
import { uebersicht } from "./uebersicht.js";
|
||||
import { aufgabenKalender, baustellenKalender } from "./kalender.js";
|
||||
import { TABELLEN } from "./tabellen.js";
|
||||
import { EinstellungenSchema, type Einstellungen } from "./einstellungen.js";
|
||||
import { liquiditaet } from "../domain/liquiditaet.js";
|
||||
@@ -178,6 +180,28 @@ export async function baueApp(o: Optionen): Promise<FastifyInstance> {
|
||||
kontostandErfasst: e.startsaldo !== 0 || e.startsaldoDatum !== null });
|
||||
});
|
||||
|
||||
// T11: Kalender-Abos. Ohne Anmeldung erreichbar (Outlook classic kann das nicht), geschützt durch das Geheimnis im Link
|
||||
const KalenderParam = z.object({ token: z.string().min(20).max(100), name: z.enum(["baustellen.ics", "aufgaben.ics"]) });
|
||||
app.get("/kalender/:token/:name", async (req, reply) => {
|
||||
const q = KalenderParam.safeParse(req.params);
|
||||
const e = await ladeEinstellungen();
|
||||
const soll = Buffer.from(e.kalenderToken ?? "");
|
||||
const ist = Buffer.from(q.success ? q.data.token : "");
|
||||
if (!q.success || !e.kalenderToken || soll.length !== ist.length || !timingSafeEqual(soll, ist)) {
|
||||
return reply.status(404).send({ fehler: "Nicht gefunden" });
|
||||
}
|
||||
const ics = q.data.name === "baustellen.ics" ? await baustellenKalender(pool, { tage: e.arbeitstage }) : await aufgabenKalender(pool);
|
||||
return reply.header("content-type", "text/calendar; charset=utf-8").header("cache-control", "no-store").send(ics);
|
||||
});
|
||||
|
||||
// Neues Geheimnis für die Kalender-Links; alte Abos hören dann auf zu funktionieren
|
||||
app.post("/api/kalender/neu", async (req) => {
|
||||
const e = await ladeEinstellungen();
|
||||
const neu = { ...e, kalenderToken: randomBytes(24).toString("base64url") };
|
||||
await transaktion(pool, benutzer(req), (c) => c.query("update einstellungen set daten = $1", [neu]));
|
||||
return { kalenderToken: neu.kalenderToken };
|
||||
});
|
||||
|
||||
app.get("/api/terminplan", async () => {
|
||||
const e = await ladeEinstellungen();
|
||||
return terminplan(pool, { tage: e.arbeitstage });
|
||||
|
||||
Reference in New Issue
Block a user