From 9abd3de3517926ad126005b678ba0a2f2776dd0d Mon Sep 17 00:00:00 2001 From: cschlaefke Date: Sun, 19 Jul 2026 15:48:36 +0200 Subject: [PATCH] =?UTF-8?q?Tempor=C3=A4re=20Diagnose-Function=20entfernt?= =?UTF-8?q?=20=E2=80=93=20Push-Strecke=20verifiziert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- functions/src/debug.ts | 68 ------------------------------------------ functions/src/index.ts | 1 - 2 files changed, 69 deletions(-) delete mode 100644 functions/src/debug.ts diff --git a/functions/src/debug.ts b/functions/src/debug.ts deleted file mode 100644 index 207de58..0000000 --- a/functions/src/debug.ts +++ /dev/null @@ -1,68 +0,0 @@ -import {onRequest} from "firebase-functions/v2/https"; -import * as admin from "firebase-admin"; - -/** - * TEMPORÄRE Diagnose-Funktion für die Push-Strecke. Wird nach dem Debugging - * wieder entfernt. Zugriff nur mit zufälligem Token (kein Erraten möglich); - * gibt keine sensiblen Inhalte zurück. - * - * ?mode=diagnose → Zustand aller Nutzer (Tokens, Zeiten, Slot-Rechnung) - * ?mode=send → schickt sofort eine Test-Push an alle Nutzer-Tokens - */ -const DEBUG_TOKEN = "lftm-dbg-xK92mQ7pW4nT"; - -export const debugReminders = onRequest( - {region: "europe-west3"}, - async (req, res) => { - if (req.query.token !== DEBUG_TOKEN) { - res.status(403).send("forbidden"); - return; - } - const db = admin.firestore(); - const now = new Date(); - const users = await db.collection("users").get(); - const report: unknown[] = []; - - for (const userDoc of users.docs) { - const user = userDoc.data(); - const tokens: string[] = user.fcmTokens ?? []; - const timezone: string = user.timezone ?? "Europe/Berlin"; - const reminderTime: string = user.reminderTime ?? "09:00"; - - const local = new Intl.DateTimeFormat("en-GB", { - timeZone: timezone, - hour: "2-digit", - minute: "2-digit", - hour12: false, - }).format(now); - - const entry: Record = { - uid: userDoc.id, - tokenCount: tokens.length, - tokenPreviews: tokens.map((t) => t.slice(0, 12) + "…"), - reminderTime, - timezone, - localNow: local, - householdId: user.householdId ?? null, - lastReminderSentOn: user.lastReminderSentOn ?? null, - }; - - if (req.query.mode === "send" && tokens.length > 0) { - const response = await admin.messaging().sendEachForMulticast({ - tokens, - notification: { - title: "Test-Push von LeafItToMe 🌱", - body: "Wenn du das liest, funktioniert die Push-Strecke.", - }, - apns: {payload: {aps: {sound: "default"}}}, - android: {notification: {defaultSound: true}, priority: "high"}, - }); - entry.sendResults = response.responses.map((r) => - r.success ? "ok" : `${r.error?.code}: ${r.error?.message}` - ); - } - report.push(entry); - } - res.json({now: now.toISOString(), users: report}); - } -); diff --git a/functions/src/index.ts b/functions/src/index.ts index 4d60b8e..052a94e 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -5,7 +5,6 @@ import * as admin from "firebase-admin"; admin.initializeApp(); export {sendDailyReminders} from "./reminders"; -export {debugReminders} from "./debug"; // Secrets liegen im Google Secret Manager (firebase functions:secrets:set), // niemals im Code oder in der App.