use original request sources for endpoint conditions

This commit is contained in:
fawney19
2026-05-06 23:48:31 +08:00
parent e2bffbbaca
commit 4e9f063385
31 changed files with 524 additions and 135 deletions
@@ -1,6 +1,6 @@
import type { BodyRuleCondition, BodyRuleConditionOp } from '@/api/endpoints'
export type ConditionSource = 'current' | 'original'
export type ConditionSource = 'body' | 'request_headers'
export type ConditionGroupMode = 'all' | 'any'
export interface EditableConditionLeaf {
@@ -46,7 +46,7 @@ export function createEmptyConditionLeaf(): EditableConditionLeaf {
path: '',
op: 'eq',
value: '',
source: 'current',
source: 'body',
}
}
@@ -86,6 +86,7 @@ export function conditionToEditable(condition?: BodyRuleCondition | null): Edita
condition.any.map(child => conditionToEditable(child) || createEmptyConditionLeaf()),
)
}
const source = (condition as { source?: unknown }).source
return {
kind: 'leaf',
path: condition.path || '',
@@ -93,7 +94,9 @@ export function conditionToEditable(condition?: BodyRuleCondition | null): Edita
value: condition.value !== undefined
? (typeof condition.value === 'string' ? condition.value : JSON.stringify(condition.value))
: '',
source: condition.source === 'original' ? 'original' : 'current',
source: source === 'request_headers' || source === 'headers'
? 'request_headers'
: 'body',
}
}
@@ -114,7 +117,7 @@ export function editableConditionToApi(node: EditableConditionNode | null): Body
const base = {
path,
op: node.op,
...(node.source === 'original' ? { source: 'original' as const } : {}),
...(node.source === 'request_headers' ? { source: 'request_headers' as const } : {}),
}
if (node.op === 'exists' || node.op === 'not_exists') {