mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
📂 refactor: File Type Inference for Frontend File Validation (#10807)
Some checks failed
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled
Some checks failed
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled
- Introduced `inferMimeType` utility to improve MIME type detection for uploaded files, including support for HEIC and HEIF formats. - Updated DragDropModal to utilize the new inference logic for validating file types, ensuring compatibility with various document upload providers. - Added comprehensive tests for `inferMimeType` to cover various scenarios, including handling of unknown extensions and preserving browser-provided types.
This commit is contained in:
parent
754b495fb8
commit
f55bd6f99b
4 changed files with 101 additions and 19 deletions
|
|
@ -200,6 +200,27 @@ export const codeTypeMapping: { [key: string]: string } = {
|
|||
tsv: 'text/tab-separated-values',
|
||||
};
|
||||
|
||||
/** Maps image extensions to MIME types for formats browsers may not recognize */
|
||||
export const imageTypeMapping: { [key: string]: string } = {
|
||||
heic: 'image/heic',
|
||||
heif: 'image/heif',
|
||||
};
|
||||
|
||||
/**
|
||||
* Infers the MIME type from a file's extension when the browser doesn't recognize it
|
||||
* @param fileName - The name of the file including extension
|
||||
* @param currentType - The current MIME type reported by the browser (may be empty)
|
||||
* @returns The inferred MIME type if browser didn't provide one, otherwise the original type
|
||||
*/
|
||||
export function inferMimeType(fileName: string, currentType: string): string {
|
||||
if (currentType) {
|
||||
return currentType;
|
||||
}
|
||||
|
||||
const extension = fileName.split('.').pop()?.toLowerCase() ?? '';
|
||||
return codeTypeMapping[extension] || imageTypeMapping[extension] || currentType;
|
||||
}
|
||||
|
||||
export const retrievalMimeTypes = [
|
||||
/^(text\/(x-c|x-c\+\+|x-h|html|x-java|markdown|x-php|x-python|x-script\.python|x-ruby|x-tex|plain|vtt|xml))$/,
|
||||
/^(application\/(json|pdf|vnd\.openxmlformats-officedocument\.(wordprocessingml\.document|presentationml\.presentation)))$/,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue