MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / resolveProjectPath

Function resolveProjectPath

packages/studio-server/src/routes/files.ts:110–137  ·  view source on GitHub ↗

Resolve project + safe absolute path for any project-scoped route.

(
  c: RouteContext,
  adapter: StudioApiAdapter,
  pathPrefix: (projectId: string) => string,
  opts?: { mustExist?: boolean },
)

Source from the content-addressed store, hash-verified

108
109/** Resolve project + safe absolute path for any project-scoped route. */
110async function resolveProjectPath(
111 c: RouteContext,
112 adapter: StudioApiAdapter,
113 pathPrefix: (projectId: string) => string,
114 opts?: { mustExist?: boolean },
115) {
116 const id = c.req.param("id");
117 const project = await adapter.resolveProject(id);
118 if (!project) {
119 return { error: c.json({ error: "not found" }, 404) } as const;
120 }
121
122 const filePath = decodeURIComponent(c.req.path.replace(pathPrefix(project.id), ""));
123 if (filePath.includes("\0")) {
124 return { error: c.json({ error: "forbidden" }, 403) } as const;
125 }
126
127 const absPath = resolveWithinProject(project.dir, filePath);
128 if (!absPath) {
129 return { error: c.json({ error: "forbidden" }, 403) } as const;
130 }
131
132 if (opts?.mustExist && !existsSync(absPath)) {
133 return { error: c.json({ error: "not found" }, 404) } as const;
134 }
135
136 return { project, filePath, absPath } as const;
137}
138
139function resolveProjectFile(
140 c: RouteContext,

Callers 3

resolveProjectFileFunction · 0.85
registerFileRoutesFunction · 0.85

Calls 2

resolveWithinProjectFunction · 0.85
resolveProjectMethod · 0.80

Tested by

no test coverage detected