mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 06:45:58 +08:00
switch endpoint service state
This commit is contained in:
parent
b1771194cc
commit
37f55098fe
@ -6,6 +6,10 @@ import ActionButton from '@/app/components/base/action-button'
|
|||||||
import CopyBtn from '@/app/components/base/copy-btn'
|
import CopyBtn from '@/app/components/base/copy-btn'
|
||||||
import Indicator from '@/app/components/header/indicator'
|
import Indicator from '@/app/components/header/indicator'
|
||||||
import Switch from '@/app/components/base/switch'
|
import Switch from '@/app/components/base/switch'
|
||||||
|
import {
|
||||||
|
disableEndpoint,
|
||||||
|
enableEndpoint,
|
||||||
|
} from '@/service/plugins'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
data: EndpointListItem
|
data: EndpointListItem
|
||||||
@ -16,9 +20,37 @@ const EndpointCard = ({
|
|||||||
}: Props) => {
|
}: Props) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [active, setActive] = useState(data.enabled)
|
const [active, setActive] = useState(data.enabled)
|
||||||
|
const endpointID = data.id
|
||||||
|
|
||||||
const handleSwitch = () => {
|
const activeEndpoint = async () => {
|
||||||
setActive(!active)
|
try {
|
||||||
|
await enableEndpoint({
|
||||||
|
url: '/workspaces/current/endpoints/enable',
|
||||||
|
endpointID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
setActive(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const inactiveEndpoint = async () => {
|
||||||
|
try {
|
||||||
|
await disableEndpoint({
|
||||||
|
url: '/workspaces/current/endpoints/disable',
|
||||||
|
endpointID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
setActive(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const handleSwitch = (state: boolean) => {
|
||||||
|
if (state)
|
||||||
|
activeEndpoint()
|
||||||
|
else
|
||||||
|
inactiveEndpoint()
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user