( filePath: string, organizationId: string | null, projectId: string, gitBranch: string, baseUrl: string, authToken: string )
| 108 | |
| 109 | // API operations |
| 110 | async 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 | |
| 164 | async function fetchManifest( |
| 165 | organizationId: string | null, |
no test coverage detected