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
|
|
@ -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.
|
||||
*
|
||||
* @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 {boolean} options.isAvatar - Whether this is an avatar upload
|
||||
* @param {boolean} options.isImage - Whether this is an image upload
|
||||
* @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
|
||||
* // Legacy single strategy
|
||||
|
|
@ -19,30 +19,25 @@ const { FileContext } = require('librechat-data-provider');
|
|||
* getFileStrategy(
|
||||
* {
|
||||
* fileStrategy: 's3',
|
||||
* fileStrategies: { avatar: 'local', document: 's3' }
|
||||
* fileStrategies: { avatar: FileSources.local, document: 's3' }
|
||||
* },
|
||||
* { isAvatar: true }
|
||||
* ) // Returns 'local'
|
||||
* ) // Returns FileSources.local
|
||||
*/
|
||||
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
|
||||
if (!config?.fileStrategies) {
|
||||
return fileStrategy || 'local'; // Default to 'local' if undefined
|
||||
if (!appConfig?.fileStrategies) {
|
||||
return appConfig.fileStrategy || FileSources.local; // Default to FileSources.local if undefined
|
||||
}
|
||||
|
||||
const strategies = config.fileStrategies;
|
||||
const defaultStrategy = strategies.default || fileStrategy || 'local';
|
||||
const strategies = appConfig.fileStrategies;
|
||||
const defaultStrategy = strategies.default || appConfig.fileStrategy || FileSources.local;
|
||||
|
||||
// Priority order for strategy selection:
|
||||
// 1. Specific file type strategy
|
||||
// 2. Default strategy from fileStrategies
|
||||
// 3. Legacy fileStrategy
|
||||
// 4. 'local' as final fallback
|
||||
// 4. FileSources.local as final fallback
|
||||
|
||||
let selectedStrategy;
|
||||
|
||||
|
|
@ -55,7 +50,7 @@ function getFileStrategy(appConfig, { isAvatar = false, isImage = false, context
|
|||
selectedStrategy = strategies.document || defaultStrategy;
|
||||
}
|
||||
|
||||
return selectedStrategy || 'local'; // Final fallback to 'local'
|
||||
return selectedStrategy || FileSources.local; // Final fallback to FileSources.local
|
||||
}
|
||||
|
||||
module.exports = { getFileStrategy };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue