fix: 自定义规则置顶生效,写入前校验策略名存在

规则首条匹配即生效,自定义规则此前插在模板规则之后、FINAL 之前,被
download.conf 等宽泛规则集抢先命中(brew.sh 配了代理仍直连)。现在新建
规则插到 seq 0,重新播种时也把自定义规则整体排在模板规则之前。

同时把 BUILTIN_POLICIES 提到 shared 共用,规则新建/编辑时校验策略必须是
内置策略或已有策略组,避免引用不存在的策略被 IR 静默剔除;前端表单默认
策略由不存在的「Proxy」改为 DIRECT。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-03 16:44:40 +08:00
parent a30360ab38
commit c6db237448
5 changed files with 29 additions and 33 deletions

View File

@@ -1,7 +1,7 @@
import { asc, eq } from 'drizzle-orm';
import { db } from '../db/index.js';
import { groupMembers, nodes, policyGroups, rules, rulesets, settings } from '../db/schema.js';
import type { NodeDto } from '@proxy-station/shared';
import { BUILTIN_POLICIES, type NodeDto } from '@proxy-station/shared';
import { rowToDto } from '../routes/nodes.js';
export interface GroupIR {
@@ -71,9 +71,9 @@ export function buildProfileIR(opts: { nodeIds?: string[] } = {}): ProfileIR {
// 停用的组从输出中剔除;引用它的成员与规则一并跳过,保证产物有效
const groupRows = allGroupRows.filter((g) => g.enabled);
const liveNames = new Set(groupRows.map((g) => g.name));
const BUILTIN_POLICIES = new Set(['DIRECT', 'REJECT', 'REJECT-DROP', 'REJECT-NO-DROP', 'REJECT-TINYGIF']);
const builtins = new Set<string>(BUILTIN_POLICIES);
/** 组已被删除或停用时,引用它的成员/规则应当跳过 */
const isDeadRef = (name: string) => !liveNames.has(name) && !BUILTIN_POLICIES.has(name);
const isDeadRef = (name: string) => !liveNames.has(name) && !builtins.has(name);
const groups: GroupIR[] = groupRows.map((g) => ({
name: g.name,
type: g.type,