SPB Git

Repository Public

bootstrap.ts 941 B 20 lines typescript

1// First-run initialisation (idempotent): database, built-in sources, and an owner password if none exists.2// The generated password is written once to $DATA_DIR/initial-password.txt (mode 600) — change it from Admin → Sécurité, then delete the file.3import crypto from "node:crypto";4import fs from "node:fs";5import path from "node:path";6import { closeDb, db } from "@/server/db";7import { hasPassword, setPassword } from "@/server/auth";8import { env } from "@/server/env";9import { ensureBuiltinSources } from "@/server/sync";1011db(); ensureBuiltinSources();12if (!hasPassword()) {13  const pw = process.env.SPTV_PASSWORD || crypto.randomBytes(18).toString("base64url");14  setPassword(pw);15  const file = path.join(env.dataDir, "initial-password.txt");16  fs.writeFileSync(file, `${pw}\n`, { mode: 0o600 });17  console.log(`  mot de passe initial écrit dans ${file}`);18} else console.log("  mot de passe déjà défini");19closeDb();20
Files main
Menu

Theme