fix: show live ticker across app and website and suppress review emails
This commit is contained in:
42
scripts/setup-playstore-review.js
Normal file
42
scripts/setup-playstore-review.js
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env node
|
||||
import 'dotenv/config'
|
||||
import { promises as fs } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import crypto from 'node:crypto'
|
||||
import { decryptObject } from '../server/utils/encryption.js'
|
||||
import { hashPassword, writeUsers } from '../server/utils/auth.js'
|
||||
|
||||
// Run in the target installation's root, with its encryption key loaded.
|
||||
const email = String(process.env.PLAYSTORE_REVIEW_EMAIL || 'playstore-review@harheimertc.invalid').trim().toLowerCase()
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) throw new Error('Ungültige PLAYSTORE_REVIEW_EMAIL')
|
||||
if (!process.env.ENCRYPTION_KEY) throw new Error('ENCRYPTION_KEY der Zielinstallation fehlt')
|
||||
const root = process.cwd().endsWith('.output') ? path.resolve('..') : process.cwd()
|
||||
const file = path.join(root, 'server/data/users.json')
|
||||
// Fail closed: never replace an unreadable user database with an empty list.
|
||||
const raw = await fs.readFile(file, 'utf8')
|
||||
let users
|
||||
try { users = JSON.parse(raw) } catch { users = decryptObject(raw, process.env.ENCRYPTION_KEY) }
|
||||
if (!Array.isArray(users)) throw new Error('Ungültiges Format der Benutzerdaten')
|
||||
let user = users.find(candidate => String(candidate.email || '').trim().toLowerCase() === email)
|
||||
if (user && user.accountType !== 'playstore_review') throw new Error('E-Mail wird bereits von einem regulären Konto verwendet')
|
||||
if (user && !process.env.PLAYSTORE_REVIEW_PASSWORD) {
|
||||
console.log(`Review-Konto existiert bereits: ${email}. Passwort bleibt unverändert.`)
|
||||
} else {
|
||||
const password = process.env.PLAYSTORE_REVIEW_PASSWORD || crypto.randomBytes(24).toString('base64url')
|
||||
if (password.length < 16) throw new Error('Review-Passwort muss mindestens 16 Zeichen haben')
|
||||
if (!user) {
|
||||
user = { id: crypto.randomUUID(), email, created: new Date().toISOString() }
|
||||
users.push(user)
|
||||
}
|
||||
Object.assign(user, {
|
||||
name: 'Google Play Review', password: await hashPassword(password),
|
||||
roles: ['mitglied'], active: true, hidden: true, accountType: 'playstore_review',
|
||||
visibility: { showBirthday: false }
|
||||
})
|
||||
delete user.role
|
||||
await fs.copyFile(file, `${file}.before-playstore-${Date.now()}`)
|
||||
if (!await writeUsers(users)) throw new Error('Review-Konto konnte nicht gespeichert werden')
|
||||
console.log(`E-Mail: ${email}`)
|
||||
if (!process.env.PLAYSTORE_REVIEW_PASSWORD) console.log(`Passwort (sicher ablegen): ${password}`)
|
||||
else console.log('Passwort: aus PLAYSTORE_REVIEW_PASSWORD gesetzt')
|
||||
}
|
||||
Reference in New Issue
Block a user