Skip to content

Commit 7cd6a5d

Browse files
committed
【功能新增】AI:知识库文档上传:20%,UploadStep 基本搭建出来
1 parent b7d7b11 commit 7cd6a5d

File tree

3 files changed

+282
-183
lines changed

3 files changed

+282
-183
lines changed

src/utils/index.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,64 @@ export function toAnyString() {
116116
return str
117117
}
118118

119+
/**
120+
* 根据支持的文件类型生成 accept 属性值
121+
*
122+
* @param supportedFileTypes 支持的文件类型数组,如 ['PDF', 'DOC', 'DOCX']
123+
* @returns 用于文件上传组件 accept 属性的字符串
124+
*/
125+
export const generateAcceptedFileTypes = (supportedFileTypes: string[]): string => {
126+
const allowedExtensions = supportedFileTypes.map((ext) => ext.toLowerCase())
127+
const mimeTypes: string[] = []
128+
129+
// 添加常见的 MIME 类型映射
130+
if (allowedExtensions.includes('txt')) {
131+
mimeTypes.push('text/plain')
132+
}
133+
if (allowedExtensions.includes('pdf')) {
134+
mimeTypes.push('application/pdf')
135+
}
136+
if (allowedExtensions.includes('html') || allowedExtensions.includes('htm')) {
137+
mimeTypes.push('text/html')
138+
}
139+
if (allowedExtensions.includes('csv')) {
140+
mimeTypes.push('text/csv')
141+
}
142+
if (allowedExtensions.includes('xlsx') || allowedExtensions.includes('xls')) {
143+
mimeTypes.push('application/vnd.ms-excel')
144+
mimeTypes.push('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
145+
}
146+
if (allowedExtensions.includes('docx') || allowedExtensions.includes('doc')) {
147+
mimeTypes.push('application/msword')
148+
mimeTypes.push('application/vnd.openxmlformats-officedocument.wordprocessingml.document')
149+
}
150+
if (allowedExtensions.includes('pptx') || allowedExtensions.includes('ppt')) {
151+
mimeTypes.push('application/vnd.ms-powerpoint')
152+
mimeTypes.push('application/vnd.openxmlformats-officedocument.presentationml.presentation')
153+
}
154+
if (allowedExtensions.includes('xml')) {
155+
mimeTypes.push('application/xml')
156+
mimeTypes.push('text/xml')
157+
}
158+
if (allowedExtensions.includes('md') || allowedExtensions.includes('markdown')) {
159+
mimeTypes.push('text/markdown')
160+
}
161+
if (allowedExtensions.includes('epub')) {
162+
mimeTypes.push('application/epub+zip')
163+
}
164+
if (allowedExtensions.includes('eml')) {
165+
mimeTypes.push('message/rfc822')
166+
}
167+
if (allowedExtensions.includes('msg')) {
168+
mimeTypes.push('application/vnd.ms-outlook')
169+
}
170+
171+
// 添加文件扩展名
172+
const extensions = allowedExtensions.map((ext) => `.${ext}`)
173+
174+
return [...mimeTypes, ...extensions].join(',')
175+
}
176+
119177
/**
120178
* 首字母大写
121179
*/

0 commit comments

Comments
 (0)