chore: enchance ext name (#1787)

This commit is contained in:
Joel 2023-12-19 14:03:24 +08:00 committed by GitHub
parent 58f8d74591
commit 8dec406161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,6 +41,38 @@ const FileUploader = ({
const { data: fileUploadConfigResponse } = useSWR({ url: '/files/upload' }, fetchFileUploadConfig)
const { data: supportFileTypesResponse } = useSWR({ url: '/files/support-type' }, fetchSupportFileTypes)
const supportTypes = supportFileTypesResponse?.allowed_extensions || []
const supportTypesShowNames = (() => {
let res = [...supportTypes]
if (res.includes('markdown') && res.includes('md'))
res = res.filter(item => item !== 'md')
if (res.includes('pptx') && res.includes('ppt'))
res = res.filter(item => item !== 'ppt')
if (res.includes('html') && res.includes('htm'))
res = res.filter(item => item !== 'htm')
res = res.map((item) => {
if (item === 'md')
return 'markdown'
if (item === 'pptx')
return 'ppt'
if (item === 'htm')
return 'html'
if (item === 'xlsx')
return 'xls'
if (item === 'docx')
return 'doc'
return item
})
return res.map(item => item.toUpperCase()).join(locale === 'en' ? ', ' : '、 ')
})()
const ACCEPTS = supportTypes.map((ext: string) => `.${ext}`)
const fileUploadConfig = useMemo(() => fileUploadConfigResponse ?? {
file_size_limit: 15,
@ -230,7 +262,7 @@ const FileUploader = ({
</div>
<div className={s.tip}>{t('datasetCreation.stepOne.uploader.tip', {
size: fileUploadConfig.file_size_limit,
supportTypes: supportTypes.map(item => item.toUpperCase()).join(locale === 'en' ? ', ' : '、 '),
supportTypes: supportTypesShowNames,
})}</div>
{dragging && <div ref={dragRef} className={s.draggingCover} />}
</div>