common.ts
Overview
The common.ts file serves as a centralized utility and constants module within the application, providing key mappings, enumerations, and lists related to file handling, language localization, platform identification, and theming. This file primarily defines static data structures such as icon mappings for file extensions, supported languages with their translations and abbreviations, MIME types for common file formats, and configuration constants for previewing files and platform/theme options.
This file is designed to be imported and used throughout the application wherever these constants or mappings are needed, thus promoting consistency and reducing hard-coded values scattered across the codebase.
Detailed Explanations
1. fileIconMap
export const fileIconMap: { [extension: string]: string }
Type: Object mapping file extensions (lowercase string keys) to corresponding icon file names (SVG).
Purpose: Provides a quick lookup for file icons based on the file extension, used in UI components showing file lists or previews.
Example Usage:
import { fileIconMap } from './common'; const fileExtension = 'pdf'; const iconFile = fileIconMap[fileExtension]; // 'pdf.svg'Details: Covers a wide range of popular file extensions including documents, images, videos, scripts, and executables.
2. LanguageList
export const LanguageList: string[]
Type: Array of strings representing supported language names in English.
Purpose: Lists all languages supported by the application for localization or language selection UI components.
Example Usage:
import { LanguageList } from './common'; LanguageList.forEach(lang => console.log(lang));
3. LanguageMap
export const LanguageMap: { [language: string]: string }
Type: Object mapping English language names to their localized display names.
Purpose: Provides localized names for languages, useful for language selection dropdowns or UI labels.
Example:
"Chinese"maps to"简体中文""Japanese"maps to"日本語"
Example Usage:
import { LanguageMap } from './common'; const displayName = LanguageMap['Chinese']; // '简体中文'
4. LanguageAbbreviation (enum)
export enum LanguageAbbreviation {
En = 'en',
Zh = 'zh',
ZhTraditional = 'zh-TRADITIONAL',
Id = 'id',
Ja = 'ja',
Es = 'es',
Vi = 'vi',
PtBr = 'pt-BR',
De = 'de',
Fr = 'fr',
}
Type: Enum defining short language codes/abbreviations.
Purpose: Standardizes language abbreviations used in the app, e.g., for locale identifiers or API parameters.
Example Usage:
import { LanguageAbbreviation } from './common'; const langCode = LanguageAbbreviation.En; // 'en'
5. LanguageAbbreviationMap
export const LanguageAbbreviationMap: { [key in LanguageAbbreviation]: string }
Type: Maps language abbreviations (enum values) to their localized language names.
Purpose: Provides a two-way mapping from abbreviations to display names.
Example Usage:
import { LanguageAbbreviation, LanguageAbbreviationMap } from './common'; const displayName = LanguageAbbreviationMap[LanguageAbbreviation.Ja]; // '日本語'
6. LanguageTranslationMap
export const LanguageTranslationMap: { [language: string]: string }
Type: Object mapping English language names to their lowercase or API-specific translation codes.
Purpose: Used for translation services or API calls requiring language codes.
Example:
"English"->"en""Portuguese BR"->"pt-br"
Example Usage:
import { LanguageTranslationMap } from './common'; const translationCode = LanguageTranslationMap['Spanish']; // 'es'
7. FileMimeType (enum)
export enum FileMimeType {
Bmp = 'image/bmp',
Csv = 'text/csv',
Odt = 'application/vnd.oasis.opendocument.text',
Doc = 'application/msword',
Docx = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
Gif = 'image/gif',
Htm = 'text/htm',
Html = 'text/html',
Jpg = 'image/jpg',
Jpeg = 'image/jpeg',
Pdf = 'application/pdf',
Png = 'image/png',
Ppt = 'application/vnd.ms-powerpoint',
Pptx = 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
Tiff = 'image/tiff',
Txt = 'text/plain',
Xls = 'application/vnd.ms-excel',
Xlsx = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
Mp4 = 'video/mp4',
Json = 'application/json',
}
Type: Enum of common MIME types for files.
Purpose: Standardizes the MIME types used across the application for file uploads, downloads, or validations.
Example Usage:
import { FileMimeType } from './common'; if (file.type === FileMimeType.Pdf) { // Handle PDF file }
8. Domain
export const Domain = 'demo.ragflow.io';
Type: String constant.
Purpose: Defines the base domain used in the application, potentially for API requests or constructing URLs.
9. File Preview Configuration
Images
export const Images: string[]
Type: List of image file extensions supported for preview.
Purpose: Defines which image types are recognized as previewable images.
Note:
'svg'is commented out, indicating it is currently excluded.
ExceptiveType
export const ExceptiveType: string[]
Type: List of file types that are exceptions from using FileViewer (likely a preview component).
Composition: Includes Excel, PDF, Word formats plus all image types from
Images.
SupportedPreviewDocumentTypes
export const SupportedPreviewDocumentTypes: string[]
Type: Alias for
ExceptiveType.Purpose: Likely used to indicate which documents can be previewed in the app without additional viewers.
10. Platform (enum)
export enum Platform {
RAGFlow = 'RAGFlow',
Dify = 'Dify',
FastGPT = 'FastGPT',
Coze = 'Coze',
}
Type: Enum listing supported platforms or products integrated or targeted by the app.
Purpose: Used for conditional handling or display depending on the platform.
Example Usage:
import { Platform } from './common'; if (currentPlatform === Platform.FastGPT) { // FastGPT-specific logic }
11. ThemeEnum (enum)
export enum ThemeEnum {
Dark = 'dark',
Light = 'light',
System = 'system',
}
Type: Enum defining UI themes supported by the application.
Purpose: Used for theming preferences and UI rendering.
Example Usage:
import { ThemeEnum } from './common'; const userTheme = ThemeEnum.System;
Implementation Details and Algorithms
The file is purely declarative, containing constants and enums without functional logic or algorithms.
The mappings and enums are designed for lookup efficiency and to ensure consistency in language codes, MIME types, and file handling across the app.
Using enums for languages, MIME types, platforms, and themes allows for type safety and autocomplete benefits in TypeScript-aware editors.
Lists like
ImagesandExceptiveTypeenable modular control over preview functionality by categorizing file types.
Interaction with Other Parts of the System
File Handling/UI Components:
fileIconMap,FileMimeType, and preview-related constants are imported by file browser, upload, or preview components to render correct icons, validate file types, and manage previews.Localization Modules:
LanguageList,LanguageMap,LanguageAbbreviation,LanguageAbbreviationMap, andLanguageTranslationMapare used by language selector components, translation modules, and API integrations that require language codes or display names.Platform-Specific Logic:
Platformenum supports conditional logic or feature toggles based on the current platform environment.Theming Components:
ThemeEnumis used in UI theming and settings components to control the user interface look and feel.Networking/API Modules:
TheDomainconstant may be used in API clients for constructing request URLs.
Visual Diagram
flowchart TD
A[fileIconMap]
B[LanguageList]
C[LanguageMap]
D[LanguageAbbreviation Enum]
E[LanguageAbbreviationMap]
F[LanguageTranslationMap]
G[FileMimeType Enum]
H[Domain]
I[Images Array]
J[ExceptiveType Array]
K[SupportedPreviewDocumentTypes Array]
L[Platform Enum]
M[ThemeEnum Enum]
B --> C
D --> E
B --> F
I --> J
J --> K
Diagram Explanation:
Shows main constants and enums as nodes.
Arrows indicate dependencies or derivations:
LanguageListis related to bothLanguageMapandLanguageTranslationMap.LanguageAbbreviationenum is linked toLanguageAbbreviationMap.ExceptiveTypearray extends fromImages.SupportedPreviewDocumentTypesis an alias ofExceptiveType.
The diagram emphasizes the grouping and relationship of language constants and file preview configurations.
Summary
The common.ts file is a foundational constants and enums module that standardizes file icons, language data, MIME types, platform identifiers, and theming options across the application. It contains no executable logic but provides essential lookup tables and enums that other modules rely on to ensure consistency, maintainability, and localization support throughout the system.