mirror of
https://github.com/langgenius/dify.git
synced 2026-02-20 09:54:44 +08:00
feat(workflow): integrate payload sanitization for workflow draft synchronization
This commit is contained in:
parent
42a9a88ae2
commit
f822b38a00
62
web/service/workflow-payload.ts
Normal file
62
web/service/workflow-payload.ts
Normal file
@ -0,0 +1,62 @@
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import type { Node } from '@/app/components/workflow/types'
|
||||
import type { FetchWorkflowDraftResponse } from '@/types/workflow'
|
||||
|
||||
export type TriggerPluginNodePayload = {
|
||||
title: string
|
||||
desc?: string
|
||||
plugin_id: string
|
||||
provider_id: string
|
||||
event_name: string
|
||||
subscription_id: string
|
||||
plugin_unique_identifier: string
|
||||
event_parameters: Record<string, unknown>
|
||||
}
|
||||
|
||||
export type WorkflowDraftSyncParams = Pick<
|
||||
FetchWorkflowDraftResponse,
|
||||
'graph' | 'features' | 'environment_variables' | 'conversation_variables'
|
||||
>
|
||||
|
||||
const sanitizeTriggerPluginNode = (node: Node<TriggerPluginNodePayload>): Node<TriggerPluginNodePayload> => {
|
||||
const data = node.data
|
||||
|
||||
if (!data || data.type !== BlockEnum.TriggerPlugin)
|
||||
return node
|
||||
|
||||
const sanitizedData: TriggerPluginNodePayload & { type: BlockEnum.TriggerPlugin } = {
|
||||
type: BlockEnum.TriggerPlugin,
|
||||
title: data.title ?? '',
|
||||
desc: data.desc,
|
||||
plugin_id: data.plugin_id ?? '',
|
||||
provider_id: data.provider_id ?? '',
|
||||
event_name: data.event_name ?? '',
|
||||
subscription_id: data.subscription_id ?? '',
|
||||
plugin_unique_identifier: data.plugin_unique_identifier ?? '',
|
||||
event_parameters: (typeof data.event_parameters === 'object' && data.event_parameters !== null)
|
||||
? data.event_parameters as Record<string, unknown>
|
||||
: {},
|
||||
}
|
||||
|
||||
return {
|
||||
...node,
|
||||
data: sanitizedData,
|
||||
}
|
||||
}
|
||||
|
||||
export const sanitizeWorkflowDraftPayload = (params: WorkflowDraftSyncParams): WorkflowDraftSyncParams => {
|
||||
const { graph } = params
|
||||
|
||||
if (!graph?.nodes?.length)
|
||||
return params
|
||||
|
||||
const sanitizedNodes = graph.nodes.map(node => sanitizeTriggerPluginNode(node as Node<TriggerPluginNodePayload>))
|
||||
|
||||
return {
|
||||
...params,
|
||||
graph: {
|
||||
...graph,
|
||||
nodes: sanitizedNodes,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -12,6 +12,8 @@ import type { BlockEnum } from '@/app/components/workflow/types'
|
||||
import type { VarInInspect } from '@/types/workflow'
|
||||
import type { FlowType } from '@/types/common'
|
||||
import { getFlowPrefix } from './utils'
|
||||
import { sanitizeWorkflowDraftPayload } from './workflow-payload'
|
||||
import type { WorkflowDraftSyncParams } from './workflow-payload'
|
||||
|
||||
export const fetchWorkflowDraft = (url: string) => {
|
||||
return get(url, {}, { silent: true }) as Promise<FetchWorkflowDraftResponse>
|
||||
@ -19,9 +21,10 @@ export const fetchWorkflowDraft = (url: string) => {
|
||||
|
||||
export const syncWorkflowDraft = ({ url, params }: {
|
||||
url: string
|
||||
params: Pick<FetchWorkflowDraftResponse, 'graph' | 'features' | 'environment_variables' | 'conversation_variables'>
|
||||
params: WorkflowDraftSyncParams
|
||||
}) => {
|
||||
return post<CommonResponse & { updated_at: number; hash: string }>(url, { body: params }, { silent: true })
|
||||
const sanitizedParams = sanitizeWorkflowDraftPayload(params)
|
||||
return post<CommonResponse & { updated_at: number; hash: string }>(url, { body: sanitizedParams }, { silent: true })
|
||||
}
|
||||
|
||||
export const fetchNodesDefaultConfigs: Fetcher<NodesDefaultConfigsResponse, string> = (url) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user