File size: 1,137 Bytes
3f13033
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { NextRequest, NextResponse } from "next/server";
import { getAuthContext } from "@/lib/auth/session";
import { getWorkflowGenomes, getWorkflowGenome } from "@/lib/frontrunner";

export async function GET(req: NextRequest) {
  try {
    const ctx = await getAuthContext();
    const { searchParams } = new URL(req.url);
    const action = searchParams.get("action") || "list";

    if (action === "list") {
      const limit = Math.min(parseInt(searchParams.get("limit") || "100"), 100);
      const workflows = getWorkflowGenomes(ctx.orgId, limit);
      return NextResponse.json({ workflows, count: workflows.length });
    }

    if (action === "get") {
      const id = searchParams.get("id");
      if (!id) return NextResponse.json({ error: "id required" }, { status: 400 });
      const wf = getWorkflowGenome(ctx.orgId, id);
      if (!wf) return NextResponse.json({ error: "Not found" }, { status: 404 });
      return NextResponse.json(wf);
    }

    return NextResponse.json({ error: "Invalid action" }, { status: 400 });
  } catch (e: any) {
    return NextResponse.json({ error: e.message }, { status: 500 });
  }
}