mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
Fix endpoint condition source handling
This commit is contained in:
@@ -140,7 +140,7 @@ export interface BodyRuleConditionLeaf {
|
||||
path: string
|
||||
op: BodyRuleConditionOp
|
||||
value?: unknown // exists / not_exists 不需要 value
|
||||
source?: 'request_headers' // 不填表示请求体;填 request_headers 表示请求头
|
||||
source?: 'body' | 'current' | 'original' | 'request_headers' | 'headers'
|
||||
}
|
||||
|
||||
export interface BodyRuleConditionAll {
|
||||
|
||||
@@ -130,6 +130,9 @@
|
||||
<SelectItem value="body">
|
||||
请求体
|
||||
</SelectItem>
|
||||
<SelectItem value="original">
|
||||
原始请求体
|
||||
</SelectItem>
|
||||
<SelectItem value="request_headers">
|
||||
请求头
|
||||
</SelectItem>
|
||||
|
||||
@@ -1459,6 +1459,7 @@ const RESERVED_BODY_FIELDS = new Set([
|
||||
|
||||
const BODY_RULE_JSON_ACTIONS = new Set(['set', 'drop', 'rename', 'append', 'insert', 'regex_replace'])
|
||||
const CONDITION_JSON_OPS = new Set(['eq', 'neq', 'gt', 'lt', 'gte', 'lte', 'starts_with', 'ends_with', 'contains', 'matches', 'exists', 'not_exists', 'in', 'type_is'])
|
||||
const CONDITION_JSON_SOURCES = new Set(['body', 'current', 'original', 'request_headers', 'headers'])
|
||||
|
||||
function isJsonObject(value: unknown): value is Record<string, unknown> {
|
||||
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
||||
@@ -1508,8 +1509,8 @@ function validateJsonConditionShape(condition: Record<string, unknown>, label: s
|
||||
if (typeof condition.op !== 'string' || !CONDITION_JSON_OPS.has(condition.op)) {
|
||||
return `${label}.op 无效`
|
||||
}
|
||||
if (condition.source !== undefined && condition.source !== 'request_headers') {
|
||||
return `${label}.source 只能是 request_headers;请求体条件不要填写 source`
|
||||
if (condition.source !== undefined && (typeof condition.source !== 'string' || !CONDITION_JSON_SOURCES.has(condition.source))) {
|
||||
return `${label}.source 无效`
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { BodyRuleCondition, BodyRuleConditionOp } from '@/api/endpoints'
|
||||
|
||||
export type ConditionSource = 'body' | 'request_headers'
|
||||
export type ConditionSource = 'body' | 'original' | 'request_headers'
|
||||
export type ConditionGroupMode = 'all' | 'any'
|
||||
|
||||
export interface EditableConditionLeaf {
|
||||
@@ -96,6 +96,8 @@ export function conditionToEditable(condition?: BodyRuleCondition | null): Edita
|
||||
: '',
|
||||
source: source === 'request_headers' || source === 'headers'
|
||||
? 'request_headers'
|
||||
: source === 'original'
|
||||
? 'original'
|
||||
: 'body',
|
||||
}
|
||||
}
|
||||
@@ -117,7 +119,11 @@ export function editableConditionToApi(node: EditableConditionNode | null): Body
|
||||
const base = {
|
||||
path,
|
||||
op: node.op,
|
||||
...(node.source === 'request_headers' ? { source: 'request_headers' as const } : {}),
|
||||
...(node.source === 'request_headers'
|
||||
? { source: 'request_headers' as const }
|
||||
: node.source === 'original'
|
||||
? { source: 'original' as const }
|
||||
: {}),
|
||||
}
|
||||
|
||||
if (node.op === 'exists' || node.op === 'not_exists') {
|
||||
|
||||
Reference in New Issue
Block a user