MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / resolveStaticFile

Function resolveStaticFile

packages/server/src/routes/webAssets.ts:63–93  ·  view source on GitHub ↗
(
  assetsDir: string,
  pathname: string,
)

Source from the content-addressed store, hash-verified

61}
62
63async function resolveStaticFile(
64 assetsDir: string,
65 pathname: string,
66): Promise<string | undefined> {
67 let decoded: string;
68 try {
69 decoded = decodeURIComponent(pathname);
70 } catch {
71 return undefined;
72 }
73
74 const normalized = normalize(decoded).replace(/^(\.\.(?:[/\\]|$))+/, '');
75 const relative = normalized === sep ? 'index.html' : normalized.replace(/^[/\\]/, '');
76 const root = resolve(assetsDir);
77 const candidate = resolve(
78 root,
79 relative.endsWith(sep) ? join(relative, 'index.html') : relative,
80 );
81 if (candidate !== root && !candidate.startsWith(`${root}${sep}`)) {
82 return undefined;
83 }
84
85 const info = await stat(candidate).catch(() => undefined);
86 if (info?.isFile() === true) {
87 return candidate;
88 }
89 if (extname(pathname) !== '') {
90 return undefined;
91 }
92 return join(root, 'index.html');
93}
94
95function isReservedPath(pathname: string): boolean {
96 return (

Callers 1

serveWebAssetFunction · 0.85

Calls 3

normalizeFunction · 0.85
resolveFunction · 0.50
statFunction · 0.50

Tested by

no test coverage detected