mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-10 11:26:52 +08:00
feat: permission and security fixes (#5266)
This commit is contained in:
@@ -7,15 +7,15 @@ import cn from 'classnames'
|
||||
import Panel from '../panel'
|
||||
import { DataSourceType } from '../panel/types'
|
||||
import ConfigFirecrawlModal from './config-firecrawl-modal'
|
||||
import { fetchFirecrawlApiKey, removeFirecrawlApiKey } from '@/service/datasets'
|
||||
import { fetchDataSources, removeDataSourceApiKeyBinding } from '@/service/datasets'
|
||||
|
||||
import type {
|
||||
DataSourceWebsiteItem,
|
||||
DataSourceItem,
|
||||
} from '@/models/common'
|
||||
import { useAppContext } from '@/context/app-context'
|
||||
|
||||
import {
|
||||
WebsiteProvider,
|
||||
DataSourceProvider,
|
||||
} from '@/models/common'
|
||||
import Toast from '@/app/components/base/toast'
|
||||
|
||||
@@ -24,11 +24,11 @@ type Props = {}
|
||||
const DataSourceWebsite: FC<Props> = () => {
|
||||
const { t } = useTranslation()
|
||||
const { isCurrentWorkspaceManager } = useAppContext()
|
||||
const [list, setList] = useState<DataSourceWebsiteItem[]>([])
|
||||
const [sources, setSources] = useState<DataSourceItem[]>([])
|
||||
const checkSetApiKey = useCallback(async () => {
|
||||
const res = await fetchFirecrawlApiKey() as any
|
||||
const list = res.settings.filter((item: DataSourceWebsiteItem) => item.provider === WebsiteProvider.fireCrawl && !item.disabled)
|
||||
setList(list)
|
||||
const res = await fetchDataSources() as any
|
||||
const list = res.sources
|
||||
setSources(list)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
@@ -46,23 +46,33 @@ const DataSourceWebsite: FC<Props> = () => {
|
||||
hideConfig()
|
||||
}, [checkSetApiKey, hideConfig])
|
||||
|
||||
const handleRemove = useCallback(async () => {
|
||||
await removeFirecrawlApiKey(list[0].id)
|
||||
setList([])
|
||||
Toast.notify({
|
||||
type: 'success',
|
||||
message: t('common.api.remove'),
|
||||
})
|
||||
}, [list, t])
|
||||
const getIdByProvider = (provider: string): string | undefined => {
|
||||
const source = sources.find(item => item.provider === provider)
|
||||
return source?.id
|
||||
}
|
||||
|
||||
const handleRemove = useCallback((provider: string) => {
|
||||
return async () => {
|
||||
const dataSourceId = getIdByProvider(provider)
|
||||
if (dataSourceId) {
|
||||
await removeDataSourceApiKeyBinding(dataSourceId)
|
||||
setSources(sources.filter(item => item.provider !== provider))
|
||||
Toast.notify({
|
||||
type: 'success',
|
||||
message: t('common.api.remove'),
|
||||
})
|
||||
}
|
||||
}
|
||||
}, [sources, t])
|
||||
|
||||
return (
|
||||
<>
|
||||
<Panel
|
||||
type={DataSourceType.website}
|
||||
isConfigured={list.length > 0}
|
||||
isConfigured={sources.length > 0}
|
||||
onConfigure={showConfig}
|
||||
readonly={!isCurrentWorkspaceManager}
|
||||
configuredList={list.map(item => ({
|
||||
readOnly={!isCurrentWorkspaceManager}
|
||||
configuredList={sources.map(item => ({
|
||||
id: item.id,
|
||||
logo: ({ className }: { className: string }) => (
|
||||
<div className={cn(className, 'flex items-center justify-center w-5 h-5 bg-white border border-gray-100 text-xs font-medium text-gray-500 rounded ml-3')}>🔥</div>
|
||||
@@ -70,7 +80,7 @@ const DataSourceWebsite: FC<Props> = () => {
|
||||
name: 'FireCrawl',
|
||||
isActive: true,
|
||||
}))}
|
||||
onRemove={handleRemove}
|
||||
onRemove={handleRemove(DataSourceProvider.fireCrawl)}
|
||||
/>
|
||||
{isShowConfig && (
|
||||
<ConfigFirecrawlModal onSaved={handleAdded} onCancel={hideConfig} />
|
||||
|
||||
Reference in New Issue
Block a user