(value: unknown)
| 224 | } |
| 225 | |
| 226 | function parseUploadPreflightResult(value: unknown): UploadPreflightResult | undefined { |
| 227 | if (!value || typeof value !== 'object') { |
| 228 | return undefined; |
| 229 | } |
| 230 | const preflight = value as UploadPreflightResponse; |
| 231 | if (preflight.ok !== true || typeof preflight.uploadId !== 'string') { |
| 232 | return undefined; |
| 233 | } |
| 234 | if (preflight.cacheHit === true) { |
| 235 | return { |
| 236 | kind: 'cache-hit', |
| 237 | uploadId: preflight.uploadId, |
| 238 | }; |
| 239 | } |
| 240 | |
| 241 | const upload = preflight.upload; |
| 242 | if (!upload || typeof upload.url !== 'string') { |
| 243 | return undefined; |
| 244 | } |
| 245 | const headers = upload.headers ?? {}; |
| 246 | if (!isStringRecord(headers)) { |
| 247 | return undefined; |
| 248 | } |
| 249 | return { |
| 250 | kind: 'direct-upload', |
| 251 | uploadId: preflight.uploadId, |
| 252 | url: upload.url, |
| 253 | headers, |
| 254 | }; |
| 255 | } |
| 256 | |
| 257 | function isStringRecord(value: unknown): value is Record<string, string> { |
| 258 | if (!value || typeof value !== 'object' || Array.isArray(value)) { |
no test coverage detected