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

Function registerFilesRoutes

packages/server/src/routes/files.ts:73–238  ·  view source on GitHub ↗
(
  app: FilesRouteHost,
  ix: IInstantiationService,
)

Source from the content-addressed store, hash-verified

71}
72
73export function registerFilesRoutes(
74 app: FilesRouteHost,
75 ix: IInstantiationService,
76): void {
77
78 app.register(multipart, {
79 limits: {
80 fileSize: DEFAULT_MAX_UPLOAD_BYTES,
81 files: 1,
82 },
83 });
84
85 const uploadRoute = defineRoute(
86 {
87 method: 'POST',
88 path: '/files',
89 success: { data: uploadFileResponseSchema },
90 consumes: ['multipart/form-data'],
91 description: 'Upload a file',
92 tags: ['files'],
93 },
94 async (req, reply) => {
95 try {
96 const fastifyReq = req as unknown as FastifyRequestLike;
97 if (!fastifyReq.file) {
98 reply.send(
99 errEnvelope(
100 ErrorCode.VALIDATION_FAILED,
101 'multipart not initialized',
102 req.id,
103 ),
104 );
105 return;
106 }
107 const part = await fastifyReq.file();
108 if (!part) {
109 reply.send(
110 errEnvelope(
111 ErrorCode.VALIDATION_FAILED,
112 'missing `file` field',
113 req.id,
114 ),
115 );
116 return;
117 }
118
119 const nameOverride = readFieldString(part.fields['name']);
120 const expiresInSec = readFieldNumber(part.fields['expires_in_sec']);
121
122 const store = ix.invokeFunction((a) => a.get(IFileStore));
123
124 const partFile = part.file as NodeJS.ReadableStream & { truncated?: boolean };
125 let busboyTruncated = false;
126 partFile.on('limit', () => {
127 busboyTruncated = true;
128 });
129 try {
130 const meta = await store.save(

Callers 1

registerApiV1RoutesFunction · 0.90

Calls 15

defineRouteFunction · 0.90
errEnvelopeFunction · 0.90
okEnvelopeFunction · 0.90
readFieldStringFunction · 0.85
readFieldNumberFunction · 0.85
buildContentDispositionFunction · 0.85
parseRangeFunction · 0.85
readRangeHeaderFunction · 0.85
sendMappedErrorFunction · 0.70
registerMethod · 0.65
sendMethod · 0.65
invokeFunctionMethod · 0.65

Tested by

no test coverage detected