mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
📃 feat: add list-balances, remove-user, and improve User scripts (#1418)
* Refactoring opening of DB to config/helpers.js * Adding two user scripts: - 'delete-user' to remove a user definitely - 'list-balances' to show the balances of all the users
This commit is contained in:
parent
8735db0980
commit
1a95bef677
10 changed files with 137 additions and 82 deletions
48
config/delete-user.js
Normal file
48
config/delete-user.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
const path = require('path');
|
||||
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') });
|
||||
const { connectWithTimeout, askQuestion, silentExit } = require('./helpers');
|
||||
const User = require('~/models/User');
|
||||
|
||||
(async () => {
|
||||
await connectWithTimeout();
|
||||
|
||||
/**
|
||||
* Show the welcome / help menu
|
||||
*/
|
||||
console.purple('---------------');
|
||||
console.purple('Deleting a user');
|
||||
console.purple('---------------');
|
||||
|
||||
let email = '';
|
||||
if (process.argv.length >= 3) {
|
||||
email = process.argv[2];
|
||||
} else {
|
||||
email = await askQuestion('Email:');
|
||||
}
|
||||
let user = await User.findOne({ email: email });
|
||||
if (user !== null) {
|
||||
if ((await askQuestion(`Delete user ${user}?`)) === 'y') {
|
||||
user = await User.findOneAndDelete({ _id: user._id });
|
||||
if (user !== null) {
|
||||
console.yellow(`Deleted user ${user}`);
|
||||
} else {
|
||||
console.yellow(`Couldn't delete user with email ${email}`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.yellow(`Didn't find user with email ${email}`);
|
||||
}
|
||||
|
||||
silentExit(0);
|
||||
})();
|
||||
|
||||
process.on('uncaughtException', (err) => {
|
||||
if (!err.message.includes('fetch failed')) {
|
||||
console.error('There was an uncaught error:');
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
if (!err.message.includes('fetch failed')) {
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue