💻 fix(client): Allow Code Filetypes and Suppress Known Vite Warnings (#2492)

* refactor(vite): suppress known warnings

* fix: allow known code filetypes if there is a mismatch of expected type, or originalFile.type is empty

* refactor(useFileHandling): naming, use variable
This commit is contained in:
Danny Avila 2024-04-22 20:08:34 -04:00 committed by GitHub
parent 738207de50
commit f94a782b4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 55 additions and 10 deletions

View file

@ -4,6 +4,7 @@ import { useState, useEffect, useCallback } from 'react';
import {
megabyte,
EModelEndpoint,
codeTypeMapping,
mergeFileConfig,
fileConfig as defaultFileConfig,
} from 'librechat-data-provider';
@ -125,7 +126,11 @@ const useFileHandling = (params?: UseFileHandling) => {
startUploadTimer(extendedFile.file_id, extendedFile.file?.name || 'File');
const formData = new FormData();
formData.append('file', extendedFile.file as File, encodeURIComponent(extendedFile.file?.name || 'File'));
formData.append(
'file',
extendedFile.file as File,
encodeURIComponent(extendedFile.file?.name || 'File'),
);
formData.append('file_id', extendedFile.file_id);
if (extendedFile.width) {
formData.append('width', extendedFile.width?.toString());
@ -168,10 +173,12 @@ const useFileHandling = (params?: UseFileHandling) => {
for (let i = 0; i < fileList.length; i++) {
let originalFile = fileList[i];
let fileType = originalFile.type;
const extension = originalFile.name.split('.').pop() ?? '';
const knownCodeType = codeTypeMapping[extension];
// Infer MIME type for Markdown files when the type is empty
if (!fileType && originalFile.name.endsWith('.md')) {
fileType = 'text/markdown';
// Infer MIME type for Known Code files when the type is empty or a mismatch
if (knownCodeType && (!fileType || fileType !== knownCodeType)) {
fileType = knownCodeType;
}
// Check if the file type is still empty after the extension check