mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-22 19:30:15 +01:00
refactor: enhance AppConfig to include fileStrategies and update related file strategy logic
This commit is contained in:
parent
f25e4253d0
commit
8df0ecd438
3 changed files with 14 additions and 16 deletions
|
|
@ -105,6 +105,7 @@ const AppService = async () => {
|
||||||
imageOutputType,
|
imageOutputType,
|
||||||
interfaceConfig,
|
interfaceConfig,
|
||||||
turnstileConfig,
|
turnstileConfig,
|
||||||
|
fileStrategies: config.fileStrategies,
|
||||||
};
|
};
|
||||||
|
|
||||||
const agentsDefaults = agentsConfigSetup(config);
|
const agentsDefaults = agentsConfigSetup(config);
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
const { FileContext } = require('librechat-data-provider');
|
const { FileSources, FileContext } = require('librechat-data-provider');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the appropriate file storage strategy based on file type and configuration.
|
* Determines the appropriate file storage strategy based on file type and configuration.
|
||||||
*
|
*
|
||||||
* @param {Object} config - App configuration object containing fileStrategy and fileStrategies
|
* @param {AppConfig} appConfig - App configuration object containing fileStrategy and fileStrategies
|
||||||
* @param {Object} options - File context options
|
* @param {Object} options - File context options
|
||||||
* @param {boolean} options.isAvatar - Whether this is an avatar upload
|
* @param {boolean} options.isAvatar - Whether this is an avatar upload
|
||||||
* @param {boolean} options.isImage - Whether this is an image upload
|
* @param {boolean} options.isImage - Whether this is an image upload
|
||||||
* @param {string} options.context - File context from FileContext enum
|
* @param {string} options.context - File context from FileContext enum
|
||||||
* @returns {string} Storage strategy to use (e.g., 'local', 's3', 'azure')
|
* @returns {string} Storage strategy to use (e.g., FileSources.local, 's3', 'azure')
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // Legacy single strategy
|
* // Legacy single strategy
|
||||||
|
|
@ -19,30 +19,25 @@ const { FileContext } = require('librechat-data-provider');
|
||||||
* getFileStrategy(
|
* getFileStrategy(
|
||||||
* {
|
* {
|
||||||
* fileStrategy: 's3',
|
* fileStrategy: 's3',
|
||||||
* fileStrategies: { avatar: 'local', document: 's3' }
|
* fileStrategies: { avatar: FileSources.local, document: 's3' }
|
||||||
* },
|
* },
|
||||||
* { isAvatar: true }
|
* { isAvatar: true }
|
||||||
* ) // Returns 'local'
|
* ) // Returns FileSources.local
|
||||||
*/
|
*/
|
||||||
function getFileStrategy(appConfig, { isAvatar = false, isImage = false, context = null } = {}) {
|
function getFileStrategy(appConfig, { isAvatar = false, isImage = false, context = null } = {}) {
|
||||||
// Handle both old (config object) and new (`appConfig` object) calling patterns
|
|
||||||
const isAppConfig = appConfig.fileStrategy !== undefined;
|
|
||||||
const config = isAppConfig ? appConfig.config : appConfig;
|
|
||||||
const fileStrategy = isAppConfig ? appConfig.fileStrategy : appConfig.fileStrategy;
|
|
||||||
|
|
||||||
// Fallback to legacy single strategy if no granular config
|
// Fallback to legacy single strategy if no granular config
|
||||||
if (!config?.fileStrategies) {
|
if (!appConfig?.fileStrategies) {
|
||||||
return fileStrategy || 'local'; // Default to 'local' if undefined
|
return appConfig.fileStrategy || FileSources.local; // Default to FileSources.local if undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
const strategies = config.fileStrategies;
|
const strategies = appConfig.fileStrategies;
|
||||||
const defaultStrategy = strategies.default || fileStrategy || 'local';
|
const defaultStrategy = strategies.default || appConfig.fileStrategy || FileSources.local;
|
||||||
|
|
||||||
// Priority order for strategy selection:
|
// Priority order for strategy selection:
|
||||||
// 1. Specific file type strategy
|
// 1. Specific file type strategy
|
||||||
// 2. Default strategy from fileStrategies
|
// 2. Default strategy from fileStrategies
|
||||||
// 3. Legacy fileStrategy
|
// 3. Legacy fileStrategy
|
||||||
// 4. 'local' as final fallback
|
// 4. FileSources.local as final fallback
|
||||||
|
|
||||||
let selectedStrategy;
|
let selectedStrategy;
|
||||||
|
|
||||||
|
|
@ -55,7 +50,7 @@ function getFileStrategy(appConfig, { isAvatar = false, isImage = false, context
|
||||||
selectedStrategy = strategies.document || defaultStrategy;
|
selectedStrategy = strategies.document || defaultStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
return selectedStrategy || 'local'; // Final fallback to 'local'
|
return selectedStrategy || FileSources.local; // Final fallback to FileSources.local
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { getFileStrategy };
|
module.exports = { getFileStrategy };
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ export interface AppConfig {
|
||||||
webSearch?: TCustomConfig['webSearch'];
|
webSearch?: TCustomConfig['webSearch'];
|
||||||
/** File storage strategy ('local', 's3', 'firebase', 'azure_blob') */
|
/** File storage strategy ('local', 's3', 'firebase', 'azure_blob') */
|
||||||
fileStrategy: FileSources.local | FileSources.s3 | FileSources.firebase | FileSources.azure_blob;
|
fileStrategy: FileSources.local | FileSources.s3 | FileSources.firebase | FileSources.azure_blob;
|
||||||
|
/** File strategies configuration */
|
||||||
|
fileStrategies: TCustomConfig['fileStrategies'];
|
||||||
/** Registration configurations */
|
/** Registration configurations */
|
||||||
registration?: TCustomConfig['registration'];
|
registration?: TCustomConfig['registration'];
|
||||||
/** Actions configurations */
|
/** Actions configurations */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue