Temporäre Diagnose-Function entfernt – Push-Strecke verifiziert
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
876ed06a97
commit
9abd3de351
2 changed files with 0 additions and 69 deletions
|
|
@ -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<string, unknown> = {
|
|
||||||
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});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
@ -5,7 +5,6 @@ import * as admin from "firebase-admin";
|
||||||
admin.initializeApp();
|
admin.initializeApp();
|
||||||
|
|
||||||
export {sendDailyReminders} from "./reminders";
|
export {sendDailyReminders} from "./reminders";
|
||||||
export {debugReminders} from "./debug";
|
|
||||||
|
|
||||||
// Secrets liegen im Google Secret Manager (firebase functions:secrets:set),
|
// Secrets liegen im Google Secret Manager (firebase functions:secrets:set),
|
||||||
// niemals im Code oder in der App.
|
// niemals im Code oder in der App.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue