Download src/app/api/cli-tools/antigravity-mitm/alias/route.js from heyeyydss/api9nin: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/spaces/heyeyydss/api9nin/resolve/main/src/app/api/cli-tools/antigravity-mitm/alias/route.js
- Command line
-
hf download hf://spaces/heyeyydss/api9nin/src/app/api/cli-tools/antigravity-mitm/alias/route.js
-
curl -L -o route.js https://huggingface.co/spaces/heyeyydss/api9nin/resolve/main/src/app/api/cli-tools/antigravity-mitm/alias/route.js
1.79 kB
| "use server"; | |
| import { NextResponse } from "next/server"; | |
| import { getMitmAlias, setMitmAliasAll } from "@/models"; | |
| import { getMitmStatus } from "@/mitm/manager"; | |
| import { writeAliasForTool } from "@/lib/mitmAliasCache"; | |
| // GET - Get MITM aliases for a tool | |
| export async function GET(request) { | |
| try { | |
| const { searchParams } = new URL(request.url); | |
| const toolName = searchParams.get("tool"); | |
| const aliases = await getMitmAlias(toolName || undefined); | |
| return NextResponse.json({ aliases }); | |
| } catch (error) { | |
| console.log("Error fetching MITM aliases:", error.message); | |
| return NextResponse.json({ error: "Failed to fetch aliases" }, { status: 500 }); | |
| } | |
| } | |
| // PUT - Save MITM aliases for a specific tool | |
| export async function PUT(request) { | |
| try { | |
| const { tool, mappings } = await request.json(); | |
| if (!tool || !mappings || typeof mappings !== "object") { | |
| return NextResponse.json({ error: "tool and mappings required" }, { status: 400 }); | |
| } | |
| // Check if DNS is enabled for this tool | |
| const status = await getMitmStatus(); | |
| if (!status.dnsStatus || !status.dnsStatus[tool]) { | |
| return NextResponse.json( | |
| { error: `DNS must be enabled for ${tool} before editing model mappings` }, | |
| { status: 403 } | |
| ); | |
| } | |
| const filtered = {}; | |
| for (const [alias, model] of Object.entries(mappings)) { | |
| if (model && model.trim()) { | |
| filtered[alias] = model.trim(); | |
| } | |
| } | |
| await setMitmAliasAll(tool, filtered); | |
| writeAliasForTool(tool, filtered); | |
| return NextResponse.json({ success: true, aliases: filtered }); | |
| } catch (error) { | |
| console.log("Error saving MITM aliases:", error.message); | |
| return NextResponse.json({ error: "Failed to save aliases" }, { status: 500 }); | |
| } | |
| } | |