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

Function tryDirectUploadWithResume

src/remote/upload-client.ts:97–138  ·  view source on GitHub ↗
(options: {
  normalizedBase: string;
  token: string;
  artifact: PreparedUploadArtifact;
  preflight: Extract<UploadPreflightResult, { kind: 'direct-upload' }>;
  uploadAttemptId: string;
  onProgress?: UploadProgressSink;
})

Source from the content-addressed store, hash-verified

95}
96
97async function tryDirectUploadWithResume(options: {
98 normalizedBase: string;
99 token: string;
100 artifact: PreparedUploadArtifact;
101 preflight: Extract<UploadPreflightResult, { kind: 'direct-upload' }>;
102 uploadAttemptId: string;
103 onProgress?: UploadProgressSink;
104}): Promise<string | undefined> {
105 const uploadOnce = async (
106 preflight: Extract<UploadPreflightResult, { kind: 'direct-upload' }>,
107 ): Promise<string> => {
108 await uploadDirectArtifact(options.artifact, preflight, options.onProgress);
109 return await finalizeDirectUpload({
110 normalizedBase: options.normalizedBase,
111 token: options.token,
112 uploadId: preflight.uploadId,
113 });
114 };
115
116 try {
117 return await uploadOnce(options.preflight);
118 } catch (error) {
119 if (!shouldRetryDirectUpload(error)) return undefined;
120 const retryPreflight = await requestUploadPreflight({
121 normalizedBase: options.normalizedBase,
122 token: options.token,
123 artifact: options.artifact,
124 uploadAttemptId: options.uploadAttemptId,
125 });
126 if (retryPreflight?.kind === 'cache-hit') {
127 return retryPreflight.uploadId;
128 }
129 if (retryPreflight?.kind === 'direct-upload') {
130 try {
131 return await uploadOnce(retryPreflight);
132 } catch {
133 return undefined;
134 }
135 }
136 return undefined;
137 }
138}
139
140function shouldRetryDirectUpload(error: unknown): boolean {
141 if (!(error instanceof AppError)) return true;

Callers 1

uploadArtifactFunction · 0.85

Calls 3

uploadOnceFunction · 0.85
shouldRetryDirectUploadFunction · 0.85
requestUploadPreflightFunction · 0.85

Tested by

no test coverage detected