feat: dsl check plugin

This commit is contained in:
StyleZhang
2024-11-13 15:48:06 +08:00
parent edbfe27eb1
commit 577a948f42
7 changed files with 94 additions and 4 deletions

View File

@ -1,6 +1,7 @@
import { useCallback, useState } from 'react'
import type {
DebugInfo as DebugInfoTypes,
Dependency,
InstallPackageResponse,
InstalledPluginListResponse,
Permissions,
@ -16,6 +17,7 @@ import {
useQuery,
useQueryClient,
} from '@tanstack/react-query'
import { useStore as usePluginDependencyStore } from '@/app/components/workflow/plugin-dependency/store'
const NAME_SPACE = 'plugins'
@ -161,3 +163,33 @@ export const useMutationClearTaskPlugin = () => {
},
})
}
export const useMutationCheckDependenciesBeforeImportDSL = () => {
const mutation = useMutation({
mutationFn: ({ dslString, url }: { dslString?: string, url?: string }) => {
if (url) {
return post<{ leaked: Dependency[] }>(
'/apps/import/url/dependencies/check',
{
body: {
url,
},
},
)
}
return post<{ leaked: Dependency[] }>(
'/apps/import/dependencies/check',
{
body: {
data: dslString,
},
})
},
onSuccess: (data) => {
const { setDependencies } = usePluginDependencyStore.getState()
setDependencies(data.leaked || [])
},
})
return mutation
}