MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / handler

Function handler

website/api/gitlab-zip.ts:63–112  ·  view source on GitHub ↗
(req: any, res: any)

Source from the content-addressed store, hash-verified

61}
62
63export default async function handler(req: any, res: any) {
64 if (req.method !== "GET" && req.method !== "HEAD") {
65 return res.status(405).json({ error: "Method not allowed" });
66 }
67
68 const rawUrl = req.url || "";
69 const urlPath = rawUrl.split("?")[0];
70 let parsed = parseGitlabZipPath(urlPath);
71
72 if (!parsed && req.query?.project && req.query?.branch) {
73 let project = String(req.query.project);
74 try {
75 project = decodeURIComponent(project);
76 } catch {
77 // keep raw value
78 }
79 parsed = { project, branch: String(req.query.branch) };
80 }
81
82 if (!parsed) {
83 return res.status(400).json({ error: "Expected /api/gitlab-zip/:project/:branch" });
84 }
85
86 const token =
87 (typeof req.headers?.["x-gitlab-token"] === "string" && req.headers["x-gitlab-token"]) ||
88 (typeof req.headers?.["private-token"] === "string" && req.headers["private-token"]) ||
89 undefined;
90
91 try {
92 const upstream = await fetchGitlabArchive(parsed.project, parsed.branch, token || undefined);
93 res.status(upstream.statusCode);
94
95 const contentType = upstream.headers["content-type"];
96 const contentLength = upstream.headers["content-length"];
97 const disposition = upstream.headers["content-disposition"];
98 if (contentType) res.setHeader("Content-Type", contentType);
99 if (contentLength) res.setHeader("Content-Length", contentLength);
100 if (disposition) res.setHeader("Content-Disposition", disposition);
101 res.setHeader("Cache-Control", "public, max-age=300");
102
103 if (req.method === "HEAD") {
104 return res.end();
105 }
106
107 return res.end(upstream.body);
108 } catch (err: any) {
109 console.error("[gitlab-zip] Proxy error:", err);
110 return res.status(502).json({ error: "Failed to fetch GitLab archive", details: err.message });
111 }
112}

Callers

nothing calls this directly

Calls 4

parseGitlabZipPathFunction · 0.85
fetchGitlabArchiveFunction · 0.85
errorMethod · 0.80
StringClass · 0.50

Tested by

no test coverage detected