(options: {
normalizedBase: string;
token: string;
artifact: PreparedUploadArtifact;
uploadAttemptId: string;
})
| 190 | } |
| 191 | |
| 192 | async function requestUploadPreflight(options: { |
| 193 | normalizedBase: string; |
| 194 | token: string; |
| 195 | artifact: PreparedUploadArtifact; |
| 196 | uploadAttemptId: string; |
| 197 | }): Promise<UploadPreflightResult | undefined> { |
| 198 | const preflightUrl = new URL('upload/preflight', options.normalizedBase); |
| 199 | const headers: Record<string, string> = { |
| 200 | 'content-type': 'application/json', |
| 201 | }; |
| 202 | Object.assign(headers, buildDaemonHttpAuthHeaders(options.token)); |
| 203 | |
| 204 | const response = await fetch(preflightUrl, { |
| 205 | method: 'POST', |
| 206 | headers, |
| 207 | signal: AbortSignal.timeout(UPLOAD_PREFLIGHT_TIMEOUT_MS), |
| 208 | body: JSON.stringify({ |
| 209 | uploadAttemptId: options.uploadAttemptId, |
| 210 | sha256: options.artifact.sha256, |
| 211 | fileName: options.artifact.fileName, |
| 212 | sizeBytes: options.artifact.sizeBytes, |
| 213 | artifactType: options.artifact.artifactType, |
| 214 | ...(options.artifact.platform ? { platform: options.artifact.platform } : {}), |
| 215 | contentType: options.artifact.contentType, |
| 216 | }), |
| 217 | }).catch(() => undefined); |
| 218 | |
| 219 | if (!response?.ok) { |
| 220 | return undefined; |
| 221 | } |
| 222 | |
| 223 | return parseUploadPreflightResult(await response.json().catch(() => undefined)); |
| 224 | } |
| 225 | |
| 226 | function parseUploadPreflightResult(value: unknown): UploadPreflightResult | undefined { |
| 227 | if (!value || typeof value !== 'object') { |
no test coverage detected