📃 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:
Linus Gasser 2023-12-30 19:25:12 +01:00 committed by GitHub
parent 8735db0980
commit 1a95bef677
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 137 additions and 82 deletions

View file

@ -6,6 +6,7 @@ const fs = require('fs');
const path = require('path');
const readline = require('readline');
const { execSync } = require('child_process');
const { connectDb } = require('@librechat/backend/lib/db');
const askQuestion = (query) => {
const rl = readline.createInterface({
@ -43,6 +44,33 @@ const silentExit = (code = 0) => {
process.exit(code);
};
async function connectWithTimeout() {
/**
* Connect to the database
* - If it takes a while, we'll warn the user
*/
let timeout = setTimeout(() => {
console.orange(
'This is taking a while... You may need to check your connection if this fails.',
);
timeout = setTimeout(() => {
console.orange('Still going... Might as well assume the connection failed...');
timeout = setTimeout(() => {
console.orange('Error incoming in 3... 2... 1...');
}, 13000);
}, 10000);
}, 5000);
// Attempt to connect to the database
try {
console.orange('Warming up the engines...');
await connectDb();
clearTimeout(timeout);
} catch (e) {
console.error(e);
silentExit(1);
}
}
// Set the console colours
console.orange = (msg) => console.log('\x1b[33m%s\x1b[0m', msg);
console.green = (msg) => console.log('\x1b[32m%s\x1b[0m', msg);
@ -58,5 +86,6 @@ module.exports = {
askQuestion,
silentExit,
isDockerRunning,
connectWithTimeout,
deleteNodeModules,
};