chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,74 @@
|
||||
import type { PluginStatus } from '@/app/components/plugins/types'
|
||||
import { useCallback } from 'react'
|
||||
import { TaskStatus } from '@/app/components/plugins/types'
|
||||
import { useMutationClearTaskPlugin, usePluginTaskList } from '@/service/use-plugins'
|
||||
|
||||
const isUnfinishedStatus = (status: PluginStatus['status']) =>
|
||||
status === TaskStatus.pending || status === TaskStatus.running
|
||||
|
||||
export const usePluginTaskStatus = () => {
|
||||
const { pluginTasks, handleRefetch } = usePluginTaskList()
|
||||
const { mutateAsync } = useMutationClearTaskPlugin()
|
||||
const allPlugins = pluginTasks
|
||||
.map((task) =>
|
||||
task.plugins.map((plugin) => {
|
||||
return {
|
||||
...plugin,
|
||||
taskId: task.id,
|
||||
}
|
||||
}),
|
||||
)
|
||||
.flat()
|
||||
const errorPlugins: PluginStatus[] = []
|
||||
const successPlugins: PluginStatus[] = []
|
||||
const runningPlugins: PluginStatus[] = []
|
||||
|
||||
allPlugins.forEach((plugin) => {
|
||||
if (isUnfinishedStatus(plugin.status)) runningPlugins.push(plugin)
|
||||
if (plugin.status === TaskStatus.failed) errorPlugins.push(plugin)
|
||||
if (plugin.status === TaskStatus.success) successPlugins.push(plugin)
|
||||
})
|
||||
|
||||
const handleClearErrorPlugin = useCallback(
|
||||
async (taskId: string, pluginId: string) => {
|
||||
await mutateAsync({
|
||||
taskId,
|
||||
pluginId,
|
||||
})
|
||||
handleRefetch()
|
||||
},
|
||||
[mutateAsync, handleRefetch],
|
||||
)
|
||||
const totalPluginsLength = allPlugins.length
|
||||
const runningPluginsLength = runningPlugins.length
|
||||
const errorPluginsLength = errorPlugins.length
|
||||
const successPluginsLength = successPlugins.length
|
||||
|
||||
const isInstalling =
|
||||
runningPluginsLength > 0 && errorPluginsLength === 0 && successPluginsLength === 0
|
||||
const isInstallingWithSuccess =
|
||||
runningPluginsLength > 0 && successPluginsLength > 0 && errorPluginsLength === 0
|
||||
const isInstallingWithError = runningPluginsLength > 0 && errorPluginsLength > 0
|
||||
const isSuccess = successPluginsLength === totalPluginsLength && totalPluginsLength > 0
|
||||
const isFailed =
|
||||
runningPluginsLength === 0 &&
|
||||
errorPluginsLength + successPluginsLength === totalPluginsLength &&
|
||||
totalPluginsLength > 0 &&
|
||||
errorPluginsLength > 0
|
||||
|
||||
return {
|
||||
errorPlugins,
|
||||
successPlugins,
|
||||
runningPlugins,
|
||||
runningPluginsLength,
|
||||
errorPluginsLength,
|
||||
successPluginsLength,
|
||||
totalPluginsLength,
|
||||
isInstalling,
|
||||
isInstallingWithSuccess,
|
||||
isInstallingWithError,
|
||||
isSuccess,
|
||||
isFailed,
|
||||
handleClearErrorPlugin,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user