Files
KrisHD_AI/scripts/set-role.js
T
Fretux c48e1b17c4
CI / check (22) (push) Successful in 10m3s
CI / check (24) (push) Successful in 9m34s
Fix admin authorization and harden chat requests
2026-10-05 22:49:29 +02:00

19 lines
787 B
JavaScript

/** Operator-only role assignment; never exposed through an HTTP endpoint. */
import {createConfig} from "../src/config.js";
import {createDatabase} from "../src/db/index.js";
const [username, role] = process.argv.slice(2);
if (!username || !["user", "admin"].includes(role) || process.argv.length !== 4) {
console.error("Usage: npm run user:role -- <existing-username> <user|admin>");
process.exitCode = 1;
} else {
const db = createDatabase(createConfig());
try {
const result = db.prepare("UPDATE users SET role = ? WHERE username = ?").run(role, username);
if (!result.changes) throw new Error("Account not found. Register the account first.");
console.log(`Role for ${username} set to ${role}.`);
} finally {
db.close();
}
}