mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 19:05:58 +08:00
feat: add support doc extract file types
This commit is contained in:
parent
e2b1464db2
commit
1e6d5f2c48
@ -1,12 +1,18 @@
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import useSWR from 'swr'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { useContext } from 'use-context-selector'
|
||||||
import VarReferencePicker from '../_base/components/variable/var-reference-picker'
|
import VarReferencePicker from '../_base/components/variable/var-reference-picker'
|
||||||
import OutputVars, { VarItem } from '../_base/components/output-vars'
|
import OutputVars, { VarItem } from '../_base/components/output-vars'
|
||||||
|
import Split from '../_base/components/split'
|
||||||
import useConfig from './use-config'
|
import useConfig from './use-config'
|
||||||
import type { DocExtractorNodeType } from './types'
|
import type { DocExtractorNodeType } from './types'
|
||||||
|
import { fetchSupportFileTypes } from '@/service/datasets'
|
||||||
import Field from '@/app/components/workflow/nodes/_base/components/field'
|
import Field from '@/app/components/workflow/nodes/_base/components/field'
|
||||||
import { type NodePanelProps } from '@/app/components/workflow/types'
|
import { type NodePanelProps } from '@/app/components/workflow/types'
|
||||||
|
import I18n from '@/context/i18n'
|
||||||
|
import { LanguagesSupported } from '@/i18n/language'
|
||||||
|
|
||||||
const i18nPrefix = 'workflow.nodes.docExtractor'
|
const i18nPrefix = 'workflow.nodes.docExtractor'
|
||||||
|
|
||||||
@ -15,7 +21,25 @@ const Panel: FC<NodePanelProps<DocExtractorNodeType>> = ({
|
|||||||
data,
|
data,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const { locale } = useContext(I18n)
|
||||||
|
|
||||||
|
const { data: supportFileTypesResponse } = useSWR({ url: '/files/support-type' }, fetchSupportFileTypes)
|
||||||
|
const supportTypes = supportFileTypesResponse?.allowed_extensions || []
|
||||||
|
const supportTypesShowNames = (() => {
|
||||||
|
const extensionMap: { [key: string]: string } = {
|
||||||
|
md: 'markdown',
|
||||||
|
pptx: 'pptx',
|
||||||
|
htm: 'html',
|
||||||
|
xlsx: 'xlsx',
|
||||||
|
docx: 'docx',
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...supportTypes]
|
||||||
|
.map(item => extensionMap[item] || item) // map to standardized extension
|
||||||
|
.map(item => item.toLowerCase()) // convert to lower case
|
||||||
|
.filter((item, index, self) => self.indexOf(item) === index) // remove duplicates
|
||||||
|
.join(locale !== LanguagesSupported[1] ? ', ' : '、 ')
|
||||||
|
})()
|
||||||
const {
|
const {
|
||||||
readOnly,
|
readOnly,
|
||||||
inputs,
|
inputs,
|
||||||
@ -29,6 +53,7 @@ const Panel: FC<NodePanelProps<DocExtractorNodeType>> = ({
|
|||||||
<Field
|
<Field
|
||||||
title={t(`${i18nPrefix}.inputVar`)}
|
title={t(`${i18nPrefix}.inputVar`)}
|
||||||
>
|
>
|
||||||
|
<>
|
||||||
<VarReferencePicker
|
<VarReferencePicker
|
||||||
readonly={readOnly}
|
readonly={readOnly}
|
||||||
nodeId={id}
|
nodeId={id}
|
||||||
@ -38,8 +63,14 @@ const Panel: FC<NodePanelProps<DocExtractorNodeType>> = ({
|
|||||||
filterVar={filterVar}
|
filterVar={filterVar}
|
||||||
typePlaceHolder='File | Array[File]'
|
typePlaceHolder='File | Array[File]'
|
||||||
/>
|
/>
|
||||||
|
<div className='mt-1 py-0.5 text-text-tertiary body-xs-regular'>
|
||||||
|
{t(`${i18nPrefix}.supportFileTypes`, { types: supportTypesShowNames })}
|
||||||
|
<a className='text-text-accent'>{t(`${i18nPrefix}.learnMore`)}</a>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
</Field>
|
</Field>
|
||||||
</div>
|
</div>
|
||||||
|
<Split />
|
||||||
<div className='px-4 pt-4 pb-2'>
|
<div className='px-4 pt-4 pb-2'>
|
||||||
<OutputVars>
|
<OutputVars>
|
||||||
<VarItem
|
<VarItem
|
||||||
|
@ -577,6 +577,8 @@ const translation = {
|
|||||||
outputVars: {
|
outputVars: {
|
||||||
text: 'Extracted text',
|
text: 'Extracted text',
|
||||||
},
|
},
|
||||||
|
supportFileTypes: 'Support file types: {{types}}.',
|
||||||
|
learnMore: 'Learn more',
|
||||||
},
|
},
|
||||||
listFilter: {
|
listFilter: {
|
||||||
inputVar: 'Input Variable',
|
inputVar: 'Input Variable',
|
||||||
|
@ -577,6 +577,8 @@ const translation = {
|
|||||||
outputVars: {
|
outputVars: {
|
||||||
text: '提取的文本',
|
text: '提取的文本',
|
||||||
},
|
},
|
||||||
|
supportFileTypes: '支持的文件类型: {{types}}。',
|
||||||
|
learnMore: '了解更多',
|
||||||
},
|
},
|
||||||
listFilter: {
|
listFilter: {
|
||||||
inputVar: '输入变量',
|
inputVar: '输入变量',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user