mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
⚙️ fix: File Config Handling (#4664)
* chore: typing * refactor: create file filter from custom fileConfig, if provided * refactor: use logger utility to avoid overly verbose axios error logs when using RAG_API * fix(useFileHandling): use memoization/callbacks to make sure the appropriate fileConfig is used; refactor: move endpoint to first field applied to formdata * chore: update librechat-data-provider version to 0.7.54 * chore: revert type change
This commit is contained in:
parent
d60a0af878
commit
49ee88b6e8
5 changed files with 123 additions and 82 deletions
|
|
@ -30,21 +30,41 @@ const importFileFilter = (req, file, cb) => {
|
|||
}
|
||||
};
|
||||
|
||||
const fileFilter = (req, file, cb) => {
|
||||
if (!file) {
|
||||
return cb(new Error('No file provided'), false);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {import('librechat-data-provider').FileConfig | undefined} customFileConfig
|
||||
*/
|
||||
const createFileFilter = (customFileConfig) => {
|
||||
/**
|
||||
* @param {ServerRequest} req
|
||||
* @param {Express.Multer.File}
|
||||
* @param {import('multer').FileFilterCallback} cb
|
||||
*/
|
||||
const fileFilter = (req, file, cb) => {
|
||||
if (!file) {
|
||||
return cb(new Error('No file provided'), false);
|
||||
}
|
||||
|
||||
if (!defaultFileConfig.checkType(file.mimetype)) {
|
||||
return cb(new Error('Unsupported file type: ' + file.mimetype), false);
|
||||
}
|
||||
const endpoint = req.body.endpoint;
|
||||
const supportedTypes =
|
||||
customFileConfig?.endpoints?.[endpoint]?.supportedMimeTypes ??
|
||||
customFileConfig?.endpoints?.default.supportedMimeTypes ??
|
||||
defaultFileConfig?.endpoints?.[endpoint]?.supportedMimeTypes;
|
||||
|
||||
cb(null, true);
|
||||
if (!defaultFileConfig.checkType(file.mimetype, supportedTypes)) {
|
||||
return cb(new Error('Unsupported file type: ' + file.mimetype), false);
|
||||
}
|
||||
|
||||
cb(null, true);
|
||||
};
|
||||
|
||||
return fileFilter;
|
||||
};
|
||||
|
||||
const createMulterInstance = async () => {
|
||||
const customConfig = await getCustomConfig();
|
||||
const fileConfig = mergeFileConfig(customConfig?.fileConfig);
|
||||
const fileFilter = createFileFilter(fileConfig);
|
||||
return multer({
|
||||
storage,
|
||||
fileFilter,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue