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

Function serveWebAsset

packages/server/src/routes/webAssets.ts:37–61  ·  view source on GitHub ↗
(
  req: FastifyRequest,
  reply: FastifyReply,
  assetsDir: string,
)

Source from the content-addressed store, hash-verified

35}
36
37async function serveWebAsset(
38 req: FastifyRequest,
39 reply: FastifyReply,
40 assetsDir: string,
41): Promise<unknown> {
42 const requestUrl = new URL(req.url, 'http://kimi-web.local');
43 if (isReservedPath(requestUrl.pathname)) {
44 return reply.callNotFound();
45 }
46
47 const filePath = await resolveStaticFile(assetsDir, requestUrl.pathname);
48 if (filePath === undefined) {
49 return reply.code(404).type('text/plain; charset=utf-8').send('Not found');
50 }
51
52 const fileInfo = await stat(filePath).catch(() => undefined);
53 if (fileInfo === undefined || !fileInfo.isFile()) {
54 return reply.code(404).type('text/plain; charset=utf-8').send('Not found');
55 }
56
57 return reply
58 .type(mimeType(filePath))
59 .header('Content-Length', String(fileInfo.size))
60 .send(createReadStream(filePath));
61}
62
63async function resolveStaticFile(
64 assetsDir: string,

Callers 1

registerWebAssetRoutesFunction · 0.70

Calls 8

isReservedPathFunction · 0.85
resolveStaticFileFunction · 0.85
mimeTypeFunction · 0.85
sendMethod · 0.65
typeMethod · 0.65
codeMethod · 0.65
headerMethod · 0.65
statFunction · 0.50

Tested by

no test coverage detected