This repository has been archived on 2023-05-12. You can view files and clone it, but cannot push or open issues or pull requests.
media-host/scripts/remove-admin.js

40 lines
1.3 KiB
JavaScript

/*
This is not a server file, but a command system to make a user an admin via a command.
Usage (in the root of the folder): node ./scripts/remove-admin.js <username>
After making your first admin user, you can kill users by going to their profile and clicking the button.
*/
const a = process.argv.slice(2).join(" ");
const config = require("../config.json")
const {MongoClient} = require("mongodb");
const client = new MongoClient(config["db-url"], {useUnifiedTopology: true});
(async function() {
console.log("Connecting to DB...");
await client.connect();
console.log("- Connected to DB.");
console.log(`Finding account by username "${a}"`);
let db = await client.db("mediahost");
let accs = await db.collection("accounts");
let acc = await accs.findOne({username: a});
let nw = acc;
if (acc == null) {
console.log(`[error] Could not find account by username "${a}"`);
process.exit(1);
}
console.log(`- Found account (id: ${acc.id}, username: ${a})`);
nw.admin = false;
console.log(`Updating account...`);
let action = await accs.findOneAndReplace({username: a}, nw);
if (action.ok == 1) {
console.log(`User action for user "${a}" complete.`);
process.exit();
} else {
console.log(`[Error] Error for user "${a}" action: `);
console.log(action);
process.exit(1);
}
})()