( workspaceId: string, file: File, folderId?: string | null, onProgress?: (event: UploadProgressEvent) => void, signal?: AbortSignal )
| 334 | } |
| 335 | |
| 336 | async function uploadWorkspaceFile( |
| 337 | workspaceId: string, |
| 338 | file: File, |
| 339 | folderId?: string | null, |
| 340 | onProgress?: (event: UploadProgressEvent) => void, |
| 341 | signal?: AbortSignal |
| 342 | ): Promise<UploadFileResponse> { |
| 343 | let result |
| 344 | try { |
| 345 | result = await runUploadStrategy({ |
| 346 | file, |
| 347 | presignedEndpoint: `/api/workspaces/${workspaceId}/files/presigned`, |
| 348 | presignedBody: { folderId }, |
| 349 | workspaceId, |
| 350 | context: 'workspace', |
| 351 | onProgress, |
| 352 | signal, |
| 353 | }) |
| 354 | } catch (error) { |
| 355 | if (error instanceof DirectUploadError && error.code === 'FALLBACK_REQUIRED') { |
| 356 | return uploadViaApiFallback(workspaceId, file, folderId, signal) |
| 357 | } |
| 358 | throw error |
| 359 | } |
| 360 | |
| 361 | const data = await registerWithRetry(workspaceId, result, folderId, signal) |
| 362 | |
| 363 | if (!data.success || !data.file) { |
| 364 | throw new Error(data.error || 'Failed to register file') |
| 365 | } |
| 366 | return { success: true, file: data.file } |
| 367 | } |
| 368 | |
| 369 | const REGISTER_MAX_ATTEMPTS = 3 |
| 370 | const REGISTER_RETRY_DELAY_MS = 500 |
no test coverage detected