mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
* chore: linting for `loadCustomConfig` * refactor: decouple CDN init and variable/health checks from AppService * refactor: move AppService to packages/data-schemas * chore: update AppConfig import path to use data-schemas * chore: update JsonSchemaType import path to use data-schemas * refactor: update UserController to import webSearchKeys and redefine FunctionTool typedef * chore: remove AppService.js * refactor: update AppConfig interface to use Partial<TCustomConfig> and make paths and fileStrategies optional * refactor: update checkConfig function to accept Partial<TCustomConfig> * chore: fix types * refactor: move handleRateLimits to startup checks as is an effect * test: remove outdated rate limit tests from AppService.spec and add new handleRateLimits tests in checks.spec
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { RateLimitPrefix } from 'librechat-data-provider';
|
|
import type { TCustomConfig } from 'librechat-data-provider';
|
|
|
|
/**
|
|
*
|
|
* @param rateLimits
|
|
*/
|
|
export const handleRateLimits = (rateLimits?: TCustomConfig['rateLimits']) => {
|
|
if (!rateLimits) {
|
|
return;
|
|
}
|
|
|
|
const rateLimitKeys = {
|
|
fileUploads: RateLimitPrefix.FILE_UPLOAD,
|
|
conversationsImport: RateLimitPrefix.IMPORT,
|
|
tts: RateLimitPrefix.TTS,
|
|
stt: RateLimitPrefix.STT,
|
|
};
|
|
|
|
Object.entries(rateLimitKeys).forEach(([key, prefix]) => {
|
|
const rateLimit = rateLimits[key as keyof typeof rateLimitKeys];
|
|
if (rateLimit) {
|
|
setRateLimitEnvVars(prefix, rateLimit);
|
|
}
|
|
});
|
|
};
|
|
|
|
type RateLimitConfig = {
|
|
ipMax?: number | undefined;
|
|
ipWindowInMinutes?: number | undefined;
|
|
userMax?: number | undefined;
|
|
userWindowInMinutes?: number | undefined;
|
|
};
|
|
|
|
/**
|
|
* Set environment variables for rate limit configurations
|
|
*
|
|
* @param prefix - Prefix for environment variable names
|
|
* @param rateLimit - Rate limit configuration object
|
|
*/
|
|
const setRateLimitEnvVars = (prefix: string, rateLimit: RateLimitConfig) => {
|
|
const envVarsMapping = {
|
|
ipMax: `${prefix}_IP_MAX`,
|
|
ipWindowInMinutes: `${prefix}_IP_WINDOW`,
|
|
userMax: `${prefix}_USER_MAX`,
|
|
userWindowInMinutes: `${prefix}_USER_WINDOW`,
|
|
};
|
|
|
|
Object.entries(envVarsMapping).forEach(([key, envVar]) => {
|
|
const value = rateLimit[key as keyof RateLimitConfig];
|
|
if (value !== undefined) {
|
|
process.env[envVar] = value.toString();
|
|
}
|
|
});
|
|
};
|