MCPcopy Create free account
hub / github.com/pingdotgg/t3code / resolveRequestedFilePath

Function resolveRequestedFilePath

scripts/mock-update-server.ts:59–87  ·  view source on GitHub ↗
(rootRealPath: string, requestUrl: string | undefined)

Source from the content-addressed store, hash-verified

57 });
58
59const resolveRequestedFilePath = (rootRealPath: string, requestUrl: string | undefined) =>
60 Effect.gen(function* () {
61 const path = yield* Path.Path;
62 const rawPath = (requestUrl ?? "/").split("?", 1)[0] ?? "/";
63 const decodedPath = yield* Effect.try({
64 try: () => decodeURIComponent(rawPath),
65 catch: () => null,
66 }).pipe(
67 Effect.match({
68 onFailure: () => undefined,
69 onSuccess: (value) => value,
70 }),
71 );
72
73 if (!decodedPath) {
74 return undefined;
75 }
76
77 if (decodedPath.includes("\0")) {
78 return undefined;
79 }
80
81 const filePath = path.resolve(
82 rootRealPath,
83 `.${decodedPath.startsWith("/") ? decodedPath : `/${decodedPath}`}`,
84 );
85
86 return (yield* isOutsideRoot(rootRealPath, filePath)) ? undefined : filePath;
87 });
88
89const isServableFile = (rootRealPath: string, filePath: string) =>
90 Effect.gen(function* () {

Callers 1

makeMockUpdateRouteLayerFunction · 0.85

Calls 1

isOutsideRootFunction · 0.85

Tested by

no test coverage detected