mirror of https://github.com/langgenius/dify
Merge branch 'feat/plugins' of https://github.com/langgenius/dify into feat/plugins
This commit is contained in:
commit
bf2b9bb898
|
@ -1,15 +0,0 @@
|
|||
import { useRequest } from 'ahooks'
|
||||
|
||||
export const useCheckInstallStatus = () => {
|
||||
const { data, run, cancel } = useRequest(async () => {}, {
|
||||
manual: true,
|
||||
pollingInterval: 5000,
|
||||
pollingErrorRetryCount: 2,
|
||||
})
|
||||
|
||||
return {
|
||||
data,
|
||||
run,
|
||||
cancel,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useState,
|
||||
} from 'react'
|
||||
import { useRequest } from 'ahooks'
|
||||
import type { PluginTask } from '../types'
|
||||
import { fetchPluginTasks } from '@/service/plugins'
|
||||
|
||||
export const usePluginTasks = () => {
|
||||
const [pluginTasks, setPluginTasks] = useState<PluginTask[]>([])
|
||||
|
||||
const handleUpdatePluginTasks = async (callback: (tasks: PluginTask[]) => void) => {
|
||||
const { tasks } = await fetchPluginTasks()
|
||||
setPluginTasks(tasks)
|
||||
callback(tasks)
|
||||
}
|
||||
|
||||
const { run, cancel } = useRequest(handleUpdatePluginTasks, {
|
||||
manual: true,
|
||||
pollingInterval: 3000,
|
||||
pollingErrorRetryCount: 2,
|
||||
})
|
||||
|
||||
const checkHasPluginTasks = useCallback((tasks: PluginTask[]) => {
|
||||
if (!tasks.length)
|
||||
cancel()
|
||||
}, [cancel])
|
||||
|
||||
useEffect(() => {
|
||||
run(checkHasPluginTasks)
|
||||
}, [run, checkHasPluginTasks])
|
||||
|
||||
return {
|
||||
pluginTasks,
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ import InstallPluginDropdown from './install-plugin-dropdown'
|
|||
import { useUploader } from './use-uploader'
|
||||
import usePermission from './use-permission'
|
||||
import DebugInfo from './debug-info'
|
||||
import { usePluginTasks } from './hooks'
|
||||
import { useTabSearchParams } from '@/hooks/use-tab-searchparams'
|
||||
import Button from '@/app/components/base/button'
|
||||
import TabSlider from '@/app/components/base/tab-slider'
|
||||
|
@ -124,6 +125,8 @@ const PluginPage = ({
|
|||
|
||||
const { dragging, fileUploader, fileChangeHandle, removeFile } = uploaderProps
|
||||
|
||||
const { pluginTasks } = usePluginTasks()
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
|
|
|
@ -224,16 +224,22 @@ export type PluginStatus = {
|
|||
message: string
|
||||
}
|
||||
|
||||
export type PluginTask = {
|
||||
id: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
status: string
|
||||
total_plugins: number
|
||||
completed_plugins: number
|
||||
plugins: PluginStatus[]
|
||||
}
|
||||
|
||||
export type TaskStatusResponse = {
|
||||
task: {
|
||||
id: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
status: string
|
||||
total_plugins: number
|
||||
completed_plugins: number
|
||||
plugins: PluginStatus[]
|
||||
}
|
||||
task: PluginTask
|
||||
}
|
||||
|
||||
export type PluginTasksResponse = {
|
||||
tasks: PluginTask[]
|
||||
}
|
||||
|
||||
export type MetaData = {
|
||||
|
|
|
@ -10,6 +10,7 @@ import type {
|
|||
Permissions,
|
||||
PluginDeclaration,
|
||||
PluginManifestInMarket,
|
||||
PluginTasksResponse,
|
||||
TaskStatusResponse,
|
||||
UninstallPluginResponse,
|
||||
UpdateEndpointRequest,
|
||||
|
@ -101,6 +102,10 @@ export const fetchMarketplaceCollectionPlugins: Fetcher<MarketplaceCollectionPlu
|
|||
return get<MarketplaceCollectionPluginsResponse>(url)
|
||||
}
|
||||
|
||||
export const fetchPluginTasks = async () => {
|
||||
return get<PluginTasksResponse>('/workspaces/current/plugin/tasks?page=1&page_size=255')
|
||||
}
|
||||
|
||||
export const checkTaskStatus = async (taskId: string) => {
|
||||
return get<TaskStatusResponse>(`/workspaces/current/plugin/tasks/${taskId}`)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue