mirror of
https://github.com/langgenius/dify.git
synced 2026-05-02 23:28:51 +08:00
fix(datasource): load default fileExtensions for file node earlier
This commit is contained in:
parent
ca1deb8f01
commit
1f10c1f474
@ -7,3 +7,25 @@ export const BLOCK_CLASSIFICATIONS: string[] = [
|
|||||||
BlockClassificationEnum.Transform,
|
BlockClassificationEnum.Transform,
|
||||||
BlockClassificationEnum.Utilities,
|
BlockClassificationEnum.Utilities,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export const DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE = [
|
||||||
|
'txt',
|
||||||
|
'markdown',
|
||||||
|
'mdx',
|
||||||
|
'pdf',
|
||||||
|
'html',
|
||||||
|
'xlsx',
|
||||||
|
'xls',
|
||||||
|
'vtt',
|
||||||
|
'properties',
|
||||||
|
'doc',
|
||||||
|
'docx',
|
||||||
|
'csv',
|
||||||
|
'eml',
|
||||||
|
'msg',
|
||||||
|
'pptx',
|
||||||
|
'xml',
|
||||||
|
'epub',
|
||||||
|
'ppt',
|
||||||
|
'md',
|
||||||
|
]
|
||||||
|
|||||||
@ -10,13 +10,14 @@ import type {
|
|||||||
OnSelectBlock,
|
OnSelectBlock,
|
||||||
ToolWithProvider,
|
ToolWithProvider,
|
||||||
} from '../types'
|
} from '../types'
|
||||||
import type { ToolDefaultValue } from './types'
|
import type { DataSourceDefaultValue, ToolDefaultValue } from './types'
|
||||||
import Tools from './tools'
|
import Tools from './tools'
|
||||||
import { ViewType } from './view-type-select'
|
import { ViewType } from './view-type-select'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
import type { ListRef } from '@/app/components/workflow/block-selector/market-place-plugin/list'
|
import type { ListRef } from '@/app/components/workflow/block-selector/market-place-plugin/list'
|
||||||
import { getMarketplaceUrl } from '@/utils/var'
|
import { getMarketplaceUrl } from '@/utils/var'
|
||||||
import { useGlobalPublicStore } from '@/context/global-public-context'
|
import { useGlobalPublicStore } from '@/context/global-public-context'
|
||||||
|
import { DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE } from './constants'
|
||||||
|
|
||||||
type AllToolsProps = {
|
type AllToolsProps = {
|
||||||
className?: string
|
className?: string
|
||||||
@ -37,14 +38,22 @@ const DataSources = ({
|
|||||||
const pluginRef = useRef<ListRef>(null)
|
const pluginRef = useRef<ListRef>(null)
|
||||||
const wrapElemRef = useRef<HTMLDivElement>(null)
|
const wrapElemRef = useRef<HTMLDivElement>(null)
|
||||||
const handleSelect = useCallback((_: any, toolDefaultValue: ToolDefaultValue) => {
|
const handleSelect = useCallback((_: any, toolDefaultValue: ToolDefaultValue) => {
|
||||||
onSelect(BlockEnum.DataSource, toolDefaultValue && {
|
let defaultValue: DataSourceDefaultValue = {
|
||||||
plugin_id: toolDefaultValue?.provider_id,
|
plugin_id: toolDefaultValue?.provider_id,
|
||||||
provider_type: toolDefaultValue?.provider_type,
|
provider_type: toolDefaultValue?.provider_type,
|
||||||
provider_name: toolDefaultValue?.provider_name,
|
provider_name: toolDefaultValue?.provider_name,
|
||||||
datasource_name: toolDefaultValue?.tool_name,
|
datasource_name: toolDefaultValue?.tool_name,
|
||||||
datasource_label: toolDefaultValue?.tool_label,
|
datasource_label: toolDefaultValue?.tool_label,
|
||||||
title: toolDefaultValue?.title,
|
title: toolDefaultValue?.title,
|
||||||
})
|
}
|
||||||
|
// Update defaultValue with fileExtensions if this is the local file data source
|
||||||
|
if (toolDefaultValue?.provider_id === 'langgenius/file' && toolDefaultValue?.provider_name === 'file') {
|
||||||
|
defaultValue = {
|
||||||
|
...defaultValue,
|
||||||
|
fileExtensions: DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onSelect(BlockEnum.DataSource, toolDefaultValue && defaultValue)
|
||||||
}, [onSelect])
|
}, [onSelect])
|
||||||
const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures)
|
const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures)
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,7 @@ export type DataSourceDefaultValue = {
|
|||||||
datasource_name: string
|
datasource_name: string
|
||||||
datasource_label: string
|
datasource_label: string
|
||||||
title: string
|
title: string
|
||||||
|
fileExtensions?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ToolValue = {
|
export type ToolValue = {
|
||||||
|
|||||||
@ -1,27 +1,5 @@
|
|||||||
import { VarType } from '@/app/components/workflow/types'
|
import { VarType } from '@/app/components/workflow/types'
|
||||||
|
|
||||||
export const DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE = [
|
|
||||||
'txt',
|
|
||||||
'markdown',
|
|
||||||
'mdx',
|
|
||||||
'pdf',
|
|
||||||
'html',
|
|
||||||
'xlsx',
|
|
||||||
'xls',
|
|
||||||
'vtt',
|
|
||||||
'properties',
|
|
||||||
'doc',
|
|
||||||
'docx',
|
|
||||||
'csv',
|
|
||||||
'eml',
|
|
||||||
'msg',
|
|
||||||
'pptx',
|
|
||||||
'xml',
|
|
||||||
'epub',
|
|
||||||
'ppt',
|
|
||||||
'md',
|
|
||||||
]
|
|
||||||
|
|
||||||
export const COMMON_OUTPUT = [
|
export const COMMON_OUTPUT = [
|
||||||
{
|
{
|
||||||
name: 'datasource_type',
|
name: 'datasource_type',
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import type {
|
|||||||
DataSourceNodeType,
|
DataSourceNodeType,
|
||||||
ToolVarInputs,
|
ToolVarInputs,
|
||||||
} from '../types'
|
} from '../types'
|
||||||
import { DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE } from '../constants'
|
|
||||||
|
|
||||||
export const useConfig = (id: string, dataSourceList?: any[]) => {
|
export const useConfig = (id: string, dataSourceList?: any[]) => {
|
||||||
const store = useStoreApi()
|
const store = useStoreApi()
|
||||||
@ -36,7 +35,6 @@ export const useConfig = (id: string, dataSourceList?: any[]) => {
|
|||||||
handleNodeDataUpdate({
|
handleNodeDataUpdate({
|
||||||
...nodeData.data,
|
...nodeData.data,
|
||||||
_dataSourceStartToAdd: false,
|
_dataSourceStartToAdd: false,
|
||||||
fileExtensions: DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, [getNodeData, handleNodeDataUpdate])
|
}, [getNodeData, handleNodeDataUpdate])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user