-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathroute.ts
More file actions
28 lines (24 loc) · 921 Bytes
/
route.ts
File metadata and controls
28 lines (24 loc) · 921 Bytes
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
import { NextRequest, NextResponse } from "next/server";
import { getRepoTree, getDefaultBranch, parseRepoUrl } from "@/lib/github";
export async function GET(request: NextRequest) {
const { searchParams } = request.nextUrl;
const repoUrl = searchParams.get("repo");
const branch = searchParams.get("branch");
if (!repoUrl) {
return NextResponse.json({ error: "Missing repo parameter" }, { status: 400 });
}
try {
const { owner, repo } = parseRepoUrl(repoUrl);
const resolvedBranch = branch || (await getDefaultBranch(owner, repo));
const tree = await getRepoTree(owner, repo, resolvedBranch);
return NextResponse.json({
owner,
repo,
branch: resolvedBranch,
tree,
});
} catch (error) {
const message = error instanceof Error ? error.message : "Failed to fetch repository tree";
return NextResponse.json({ error: message }, { status: 500 });
}
}