| 
                        1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 | 
                        - import {
 -   useCallback,
 -   useState,
 - } from 'react'
 - import { useTranslation } from 'react-i18next'
 - import {
 -   DSL_EXPORT_CHECK,
 - } from '@/app/components/workflow/constants'
 - import { useNodesSyncDraft } from './use-nodes-sync-draft'
 - import { useEventEmitterContextContext } from '@/context/event-emitter'
 - import { fetchWorkflowDraft } from '@/service/workflow'
 - import { exportAppConfig } from '@/service/apps'
 - import { useToastContext } from '@/app/components/base/toast'
 - import { useStore as useAppStore } from '@/app/components/app/store'
 - 
 - export const useDSL = () => {
 -   const { t } = useTranslation()
 -   const { notify } = useToastContext()
 -   const { eventEmitter } = useEventEmitterContextContext()
 -   const [exporting, setExporting] = useState(false)
 -   const { doSyncWorkflowDraft } = useNodesSyncDraft()
 - 
 -   const appDetail = useAppStore(s => s.appDetail)
 - 
 -   const handleExportDSL = useCallback(async (include = false, workflowId?: string) => {
 -     if (!appDetail)
 -       return
 - 
 -     if (exporting)
 -       return
 - 
 -     try {
 -       setExporting(true)
 -       await doSyncWorkflowDraft()
 -       const { data } = await exportAppConfig({
 -         appID: appDetail.id,
 -         include,
 -         workflowID: workflowId,
 -       })
 -       const a = document.createElement('a')
 -       const file = new Blob([data], { type: 'application/yaml' })
 -       a.href = URL.createObjectURL(file)
 -       a.download = `${appDetail.name}.yml`
 -       a.click()
 -     }
 -     catch {
 -       notify({ type: 'error', message: t('app.exportFailed') })
 -     }
 -     finally {
 -       setExporting(false)
 -     }
 -   }, [appDetail, notify, t, doSyncWorkflowDraft, exporting])
 - 
 -   const exportCheck = useCallback(async () => {
 -     if (!appDetail)
 -       return
 -     try {
 -       const workflowDraft = await fetchWorkflowDraft(`/apps/${appDetail?.id}/workflows/draft`)
 -       const list = (workflowDraft.environment_variables || []).filter(env => env.value_type === 'secret')
 -       if (list.length === 0) {
 -         handleExportDSL()
 -         return
 -       }
 -       eventEmitter?.emit({
 -         type: DSL_EXPORT_CHECK,
 -         payload: {
 -           data: list,
 -         },
 -       } as any)
 -     }
 -     catch {
 -       notify({ type: 'error', message: t('app.exportFailed') })
 -     }
 -   }, [appDetail, eventEmitter, handleExportDSL, notify, t])
 - 
 -   return {
 -     exportCheck,
 -     handleExportDSL,
 -   }
 - }
 
 
  |