MCPcopy Index your code
hub / github.com/callstack/agent-device / finalizeDirectUpload

Function finalizeDirectUpload

src/remote/upload-client.ts:293–325  ·  view source on GitHub ↗
(options: {
  normalizedBase: string;
  token: string;
  uploadId: string;
})

Source from the content-addressed store, hash-verified

291}
292
293async function finalizeDirectUpload(options: {
294 normalizedBase: string;
295 token: string;
296 uploadId: string;
297}): Promise<string> {
298 const finalizeUrl = new URL('upload/finalize', options.normalizedBase);
299 const headers: Record<string, string> = {
300 'content-type': 'application/json',
301 };
302 Object.assign(headers, buildDaemonHttpAuthHeaders(options.token));
303
304 const response = await fetch(finalizeUrl, {
305 method: 'POST',
306 headers,
307 signal: AbortSignal.timeout(UPLOAD_PREFLIGHT_TIMEOUT_MS),
308 body: JSON.stringify({ uploadId: options.uploadId }),
309 }).catch((error) => {
310 throw new AppError('COMMAND_FAILED', 'Failed to finalize direct artifact upload', {}, error);
311 });
312
313 if (!response.ok) {
314 throw new AppError('COMMAND_FAILED', 'Direct artifact upload finalize failed', {
315 status: response.status,
316 statusText: response.statusText,
317 });
318 }
319
320 const parsed = (await response.json().catch(() => undefined)) as UploadResponse | undefined;
321 if (!parsed?.ok || !parsed.uploadId) {
322 throw new AppError('COMMAND_FAILED', 'Invalid upload finalize response');
323 }
324 return parsed.uploadId;
325}

Callers 1

uploadOnceFunction · 0.85

Calls 1

Tested by

no test coverage detected