robustere pfad-suche
All checks were successful
Code Analysis and Production Deploy / analyze (push) Successful in 5m47s
Code Analysis and Production Deploy / deploy-production (push) Has been skipped
Code Analysis and Production Deploy / deploy-test (push) Successful in 1m55s

This commit is contained in:
Torsten Schulz (local)
2026-06-10 16:05:15 +02:00
parent 8393f154e5
commit 7e533fae49

View File

@@ -1,5 +1,6 @@
import crypto from 'crypto' import crypto from 'crypto'
import { promises as fs } from 'fs' import { promises as fs } from 'fs'
import path from 'path'
import { readUsers, writeUsers, isHiddenUser } from './auth.js' import { readUsers, writeUsers, isHiddenUser } from './auth.js'
import { notificationSettingsForUser } from './notification-settings.js' import { notificationSettingsForUser } from './notification-settings.js'
@@ -15,13 +16,29 @@ function projectIdFromServiceAccount(serviceAccount) {
return process.env.FCM_PROJECT_ID || serviceAccount.project_id 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() { async function readServiceAccount() {
if (process.env.FCM_SERVICE_ACCOUNT_JSON) { if (process.env.FCM_SERVICE_ACCOUNT_JSON) {
return JSON.parse(process.env.FCM_SERVICE_ACCOUNT_JSON) return JSON.parse(process.env.FCM_SERVICE_ACCOUNT_JSON)
} }
if (process.env.GOOGLE_APPLICATION_CREDENTIALS) { for (const candidate of serviceAccountCandidatePaths()) {
const raw = await fs.readFile(process.env.GOOGLE_APPLICATION_CREDENTIALS, 'utf8') try {
return JSON.parse(raw) 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 return null
} }