mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-15 16:00:15 +01:00
🔄 refactor(config): Move connectWithTimeout Outside of Helpers Module (#1513)
This commit is contained in:
parent
9144680ffb
commit
050a92b318
7 changed files with 47 additions and 40 deletions
|
|
@ -1,11 +1,12 @@
|
|||
const path = require('path');
|
||||
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') });
|
||||
const { askQuestion, silentExit, connectWithTimeout } = require('./helpers');
|
||||
const { askQuestion, silentExit } = require('./helpers');
|
||||
const Transaction = require('~/models/Transaction');
|
||||
const User = require('~/models/User');
|
||||
const connect = require('./connect');
|
||||
|
||||
(async () => {
|
||||
await connectWithTimeout();
|
||||
await connect();
|
||||
|
||||
/**
|
||||
* Show the welcome / help menu
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
const path = require('path');
|
||||
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') });
|
||||
const { askQuestion, silentExit, connectWithTimeout } = require('./helpers');
|
||||
const { askQuestion, silentExit } = require('./helpers');
|
||||
const banViolation = require('~/cache/banViolation');
|
||||
const User = require('~/models/User');
|
||||
const connect = require('./connect');
|
||||
|
||||
(async () => {
|
||||
await connectWithTimeout();
|
||||
await connect();
|
||||
|
||||
console.purple('---------------------');
|
||||
console.purple('Ban a user account!');
|
||||
|
|
|
|||
32
config/connect.js
Normal file
32
config/connect.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
const path = require('path');
|
||||
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') });
|
||||
const connectDb = require('~/lib/db/connectDb');
|
||||
|
||||
async function connect() {
|
||||
/**
|
||||
* 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);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = connect;
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
const path = require('path');
|
||||
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') });
|
||||
const { registerUser } = require('~/server/services/AuthService');
|
||||
const { askQuestion, silentExit, connectWithTimeout } = require('./helpers');
|
||||
const { askQuestion, silentExit } = require('./helpers');
|
||||
const User = require('~/models/User');
|
||||
const connect = require('./connect');
|
||||
|
||||
(async () => {
|
||||
await connectWithTimeout();
|
||||
await connect();
|
||||
|
||||
/**
|
||||
* Show the welcome / help menu
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
const path = require('path');
|
||||
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') });
|
||||
const { connectWithTimeout, askQuestion, silentExit } = require('./helpers');
|
||||
const { askQuestion, silentExit } = require('./helpers');
|
||||
const User = require('~/models/User');
|
||||
const connect = require('./connect');
|
||||
|
||||
(async () => {
|
||||
await connectWithTimeout();
|
||||
await connect();
|
||||
|
||||
/**
|
||||
* Show the welcome / help menu
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ const fs = require('fs');
|
|||
const path = require('path');
|
||||
const readline = require('readline');
|
||||
const { execSync } = require('child_process');
|
||||
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') });
|
||||
const connectDb = require('~/lib/db/connectDb');
|
||||
|
||||
const askQuestion = (query) => {
|
||||
const rl = readline.createInterface({
|
||||
|
|
@ -45,33 +43,6 @@ 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);
|
||||
|
|
@ -87,6 +58,5 @@ module.exports = {
|
|||
askQuestion,
|
||||
silentExit,
|
||||
isDockerRunning,
|
||||
connectWithTimeout,
|
||||
deleteNodeModules,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
const path = require('path');
|
||||
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') });
|
||||
const { connectWithTimeout, silentExit } = require('./helpers');
|
||||
const { silentExit } = require('./helpers');
|
||||
const Balance = require('~/models/Balance');
|
||||
const User = require('~/models/User');
|
||||
const connect = require('./connect');
|
||||
|
||||
(async () => {
|
||||
await connectWithTimeout();
|
||||
await connect();
|
||||
|
||||
/**
|
||||
* Show the welcome / help menu
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue