MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / uploadFile

Function uploadFile

apps/web/src/scripts/managed-indexing/test.ts:110–162  ·  view source on GitHub ↗
(
  filePath: string,
  organizationId: string | null,
  projectId: string,
  gitBranch: string,
  baseUrl: string,
  authToken: string
)

Source from the content-addressed store, hash-verified

108
109// API operations
110async function uploadFile(
111 filePath: string,
112 organizationId: string | null,
113 projectId: string,
114 gitBranch: string,
115 baseUrl: string,
116 authToken: string
117): Promise<UploadResult> {
118 const fileContent = readFileSync(filePath);
119 const fileHash = computeFileHash(filePath);
120 const workspaceRoot = process.cwd();
121 const relativeFilePath = relative(workspaceRoot, filePath);
122
123 const formData = new FormData();
124 const blob = new Blob([fileContent], { type: 'text/plain' });
125 const file = new File([blob], relativeFilePath, { type: 'text/plain' });
126
127 formData.append('file', file);
128 if (organizationId) {
129 formData.append('organizationId', organizationId);
130 }
131 formData.append('projectId', projectId);
132 formData.append('filePath', relativeFilePath);
133 formData.append('fileHash', fileHash);
134 formData.append('gitBranch', gitBranch);
135 formData.append('isBaseBranch', 'true');
136
137 try {
138 const response = await fetch(`${baseUrl}/api/code-indexing/upsert-by-file`, {
139 method: 'PUT',
140 body: formData,
141 headers: {
142 Authorization: `Bearer ${authToken}`,
143 },
144 });
145
146 if (!response.ok) {
147 const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
148 return {
149 success: false,
150 error: errorData.error || errorData.message || `HTTP ${response.status}`,
151 };
152 }
153
154 const data = await response.json();
155 return { success: true, chunksProcessed: data.chunksProcessed };
156 } catch (error) {
157 return {
158 success: false,
159 error: error instanceof Error ? error.message : 'Unknown error',
160 };
161 }
162}
163
164async function fetchManifest(
165 organizationId: string | null,

Callers 1

indexFilesFunction · 0.85

Calls 4

computeFileHashFunction · 0.85
appendMethod · 0.65
jsonMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected