robustere pfad-suche
This commit is contained in:
@@ -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')
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user