From 7e533fae49535fc015c439184b5afeb08fe2a0dc Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 10 Jun 2026 16:05:15 +0200 Subject: [PATCH] robustere pfad-suche --- server/utils/push-notifications.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/server/utils/push-notifications.js b/server/utils/push-notifications.js index 661766f..a900563 100644 --- a/server/utils/push-notifications.js +++ b/server/utils/push-notifications.js @@ -1,5 +1,6 @@ import crypto from 'crypto' import { promises as fs } from 'fs' +import path from 'path' import { readUsers, writeUsers, isHiddenUser } from './auth.js' import { notificationSettingsForUser } from './notification-settings.js' @@ -15,13 +16,29 @@ function projectIdFromServiceAccount(serviceAccount) { return process.env.FCM_PROJECT_ID || serviceAccount.project_id } +function serviceAccountCandidatePaths() { + const filename = 'harheimer-tc-firebase-adminsdk-fbsvc-18b66a2971.json' + const cwd = process.cwd() + const candidates = [] + if (process.env.GOOGLE_APPLICATION_CREDENTIALS) candidates.push(process.env.GOOGLE_APPLICATION_CREDENTIALS) + candidates.push(path.join(cwd, 'server/data', filename)) + candidates.push(path.join(cwd, '../server/data', filename)) + return [...new Set(candidates)] +} + async function readServiceAccount() { if (process.env.FCM_SERVICE_ACCOUNT_JSON) { return JSON.parse(process.env.FCM_SERVICE_ACCOUNT_JSON) } - if (process.env.GOOGLE_APPLICATION_CREDENTIALS) { - const raw = await fs.readFile(process.env.GOOGLE_APPLICATION_CREDENTIALS, 'utf8') - return JSON.parse(raw) + for (const candidate of serviceAccountCandidatePaths()) { + try { + const raw = await fs.readFile(candidate, 'utf8') + return JSON.parse(raw) + } catch (error) { + if (error?.code !== 'ENOENT') { + console.warn(`FCM Service-Account konnte nicht gelesen werden (${candidate}): ${error.message}`) + } + } } return null }