feat: 目录进度可视化
This commit is contained in:
parent
1d5ace0fb2
commit
3c958c3d11
@ -15,6 +15,8 @@ import { FileType, KnowledgeBaseParams, KnowledgeItem } from '@types'
|
|||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
|
|
||||||
|
import { windowService } from './WindowService'
|
||||||
|
|
||||||
class KnowledgeService {
|
class KnowledgeService {
|
||||||
private storageDir = path.join(app.getPath('userData'), 'Data', 'KnowledgeBase')
|
private storageDir = path.join(app.getPath('userData'), 'Data', 'KnowledgeBase')
|
||||||
|
|
||||||
@ -83,10 +85,23 @@ class KnowledgeService {
|
|||||||
): Promise<LoaderReturn> => {
|
): Promise<LoaderReturn> => {
|
||||||
const ragApplication = await this.getRagApplication(base)
|
const ragApplication = await this.getRagApplication(base)
|
||||||
|
|
||||||
|
const sendDirectoryProcessingPercent = (totalFiles: number, processedFiles: number) => {
|
||||||
|
const mainWindow = windowService.getMainWindow()
|
||||||
|
mainWindow?.webContents.send(base.id, (processedFiles / totalFiles) * 100)
|
||||||
|
}
|
||||||
|
|
||||||
if (item.type === 'directory') {
|
if (item.type === 'directory') {
|
||||||
const directory = item.content as string
|
const directory = item.content as string
|
||||||
const files = getAllFiles(directory)
|
const files = getAllFiles(directory)
|
||||||
const loaderPromises = files.map((file) => addFileLoader(ragApplication, file, base, forceReload))
|
const totalFiles = files.length
|
||||||
|
let processedFiles = 0
|
||||||
|
const loaderPromises = files.map(async (file) => {
|
||||||
|
const result = await addFileLoader(ragApplication, file, base, forceReload)
|
||||||
|
processedFiles++
|
||||||
|
|
||||||
|
sendDirectoryProcessingPercent(totalFiles, processedFiles)
|
||||||
|
return result
|
||||||
|
})
|
||||||
const loaderResults = await Promise.all(loaderPromises)
|
const loaderResults = await Promise.all(loaderPromises)
|
||||||
const uniqueIds = loaderResults.map((result) => result.uniqueId)
|
const uniqueIds = loaderResults.map((result) => result.uniqueId)
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -198,6 +198,23 @@ export const useKnowledge = (baseId: string) => {
|
|||||||
return base?.items.filter((item) => item.type === type && item.processingStatus !== undefined) || []
|
return base?.items.filter((item) => item.type === type && item.processingStatus !== undefined) || []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取目录处理进度
|
||||||
|
const getDirectoryProcessingPercent = (itemId: string) => {
|
||||||
|
const [percent, setPercent] = useState<number>(0)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const cleanup = window.electron.ipcRenderer.on(itemId, (_, progressingPercent: number) => {
|
||||||
|
setPercent(progressingPercent)
|
||||||
|
})
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cleanup()
|
||||||
|
}
|
||||||
|
}, [itemId])
|
||||||
|
|
||||||
|
return percent
|
||||||
|
}
|
||||||
|
|
||||||
// 清除已完成的项目
|
// 清除已完成的项目
|
||||||
const clearCompleted = () => {
|
const clearCompleted = () => {
|
||||||
dispatch(clearCompletedProcessing({ baseId }))
|
dispatch(clearCompletedProcessing({ baseId }))
|
||||||
@ -280,6 +297,7 @@ export const useKnowledge = (baseId: string) => {
|
|||||||
refreshItem,
|
refreshItem,
|
||||||
getProcessingStatus,
|
getProcessingStatus,
|
||||||
getProcessingItemsByType,
|
getProcessingItemsByType,
|
||||||
|
getDirectoryProcessingPercent,
|
||||||
clearCompleted,
|
clearCompleted,
|
||||||
clearAll,
|
clearAll,
|
||||||
removeItem,
|
removeItem,
|
||||||
|
|||||||
@ -53,6 +53,7 @@ const KnowledgeContent: FC<KnowledgeContentProps> = ({ selectedBase }) => {
|
|||||||
addSitemap,
|
addSitemap,
|
||||||
removeItem,
|
removeItem,
|
||||||
getProcessingStatus,
|
getProcessingStatus,
|
||||||
|
getDirectoryProcessingPercent,
|
||||||
addNote,
|
addNote,
|
||||||
addDirectory
|
addDirectory
|
||||||
} = useKnowledge(selectedBase.id || '')
|
} = useKnowledge(selectedBase.id || '')
|
||||||
@ -63,6 +64,7 @@ const KnowledgeContent: FC<KnowledgeContentProps> = ({ selectedBase }) => {
|
|||||||
if (!base) {
|
if (!base) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
const progressingPercent = getDirectoryProcessingPercent(base?.id)
|
||||||
|
|
||||||
const handleAddFile = () => {
|
const handleAddFile = () => {
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
@ -271,7 +273,12 @@ const KnowledgeContent: FC<KnowledgeContentProps> = ({ selectedBase }) => {
|
|||||||
<FlexAlignCenter>
|
<FlexAlignCenter>
|
||||||
{item.uniqueId && <Button type="text" icon={<RefreshIcon />} onClick={() => refreshItem(item)} />}
|
{item.uniqueId && <Button type="text" icon={<RefreshIcon />} onClick={() => refreshItem(item)} />}
|
||||||
<StatusIconWrapper>
|
<StatusIconWrapper>
|
||||||
<StatusIcon sourceId={item.id} base={base} getProcessingStatus={getProcessingStatus} />
|
<StatusIcon
|
||||||
|
sourceId={item.id}
|
||||||
|
base={base}
|
||||||
|
getProcessingStatus={getProcessingStatus}
|
||||||
|
progressingPercent={progressingPercent}
|
||||||
|
/>
|
||||||
</StatusIconWrapper>
|
</StatusIconWrapper>
|
||||||
<Button type="text" danger onClick={() => removeItem(item)} icon={<DeleteOutlined />} />
|
<Button type="text" danger onClick={() => removeItem(item)} icon={<DeleteOutlined />} />
|
||||||
</FlexAlignCenter>
|
</FlexAlignCenter>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons'
|
import { CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons'
|
||||||
import { KnowledgeBase, ProcessingStatus } from '@renderer/types'
|
import { KnowledgeBase, ProcessingStatus } from '@renderer/types'
|
||||||
import { Tooltip } from 'antd'
|
import { Progress, Tooltip } from 'antd'
|
||||||
import { FC } from 'react'
|
import { FC } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
@ -9,9 +9,10 @@ interface StatusIconProps {
|
|||||||
sourceId: string
|
sourceId: string
|
||||||
base: KnowledgeBase
|
base: KnowledgeBase
|
||||||
getProcessingStatus: (sourceId: string) => ProcessingStatus | undefined
|
getProcessingStatus: (sourceId: string) => ProcessingStatus | undefined
|
||||||
|
progressingPercent?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const StatusIcon: FC<StatusIconProps> = ({ sourceId, base, getProcessingStatus }) => {
|
const StatusIcon: FC<StatusIconProps> = ({ sourceId, base, getProcessingStatus, progressingPercent }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const status = getProcessingStatus(sourceId)
|
const status = getProcessingStatus(sourceId)
|
||||||
const item = base.items.find((item) => item.id === sourceId)
|
const item = base.items.find((item) => item.id === sourceId)
|
||||||
@ -40,11 +41,7 @@ const StatusIcon: FC<StatusIconProps> = ({ sourceId, base, getProcessingStatus }
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
)
|
)
|
||||||
case 'processing':
|
case 'processing':
|
||||||
return (
|
return <Progress type="circle" size={14} percent={Number(progressingPercent?.toFixed(0))} />
|
||||||
<Tooltip title={t('knowledge.status_processing')} placement="left">
|
|
||||||
<StatusDot $status="processing" />
|
|
||||||
</Tooltip>
|
|
||||||
)
|
|
||||||
case 'completed':
|
case 'completed':
|
||||||
return (
|
return (
|
||||||
<Tooltip title={t('knowledge.status_completed')} placement="left">
|
<Tooltip title={t('knowledge.status_completed')} placement="left">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user