MCPcopy Create free account
hub / github.com/allocnode/oh-my-sage / PATCH

Function PATCH

src/app/api/graphs/route.ts:65–135  ·  view source on GitHub ↗
(request: NextRequest)

Source from the content-addressed store, hash-verified

63 error: '获取规则列表失败',
64 message: error instanceof Error ? error.message : '未知错误',
65 graphs: [],
66 }, {status: 500});
67 }
68}
69
70export async function POST(request: NextRequest) {
71 try {
72 if (!isGatewayConnected()) return NextResponse.json({success: false, error: '未连接到网关'}, {status: 400});
73 const parsed = createSchema.safeParse(await request.json());
74 if (!parsed.success) return NextResponse.json({success: false, error: '规则参数无效', details: parsed.error.issues}, {status: 400});
75 const {name, nodes, variables, enable = true} = parsed.data;
76 const result = await createGraph(getGateway()!, {name, nodes, variables, enable});
77 return NextResponse.json(result, {status: result.success ? 201 : 502});
78 } catch (error) {
79 return NextResponse.json({success: false, error: `创建规则失败: ${error}`}, {status: 500});
80 }
81}
82
83export async function PUT(request: NextRequest) {
84 try {
85 if (!isGatewayConnected()) return NextResponse.json({success: false, error: '未连接到网关'}, {status: 400});
86 const parsed = updateSchema.safeParse(await request.json());
87 if (!parsed.success) return NextResponse.json({success: false, error: '规则参数无效', details: parsed.error.issues}, {status: 400});
88 const {id, name, nodes, enable} = parsed.data;
89 const result = await updateGraph(getGateway()!, id, {name, nodes, enable});
90 return NextResponse.json(result, {status: result.success ? 200 : 502});
91 } catch (error) {
92 return NextResponse.json({success: false, error: `更新规则失败: ${error}`}, {status: 500});
93 }
94}
95
96/**
97 * PATCH 请求处理
98 * 启用/禁用规则
99 */
100export async function PATCH(request: NextRequest) {
101 try {
102 // 检查网关连接
103 if (!isGatewayConnected()) {
104 return NextResponse.json({
105 success: false,
106 error: '未连接到网关',
107 }, {status: 400});
108 }
109
110 const body = await request.json();
111 const {id, enable} = body;
112
113 if (!id) {
114 return NextResponse.json({
115 success: false,
116 error: '缺少规则 ID',
117 }, {status: 400});
118 }
119
120 if (typeof enable !== 'boolean') {
121 return NextResponse.json({
122 success: false,

Callers

nothing calls this directly

Calls 3

isGatewayConnectedFunction · 0.90
getGatewayFunction · 0.90
callApiMethod · 0.45

Tested by

no test coverage detected