(files: readonly File[], forceSend?: boolean)
| 1614 | } |
| 1615 | |
| 1616 | export async function uploadProvidedFiles(files: readonly File[], forceSend?: boolean): Promise<void> { |
| 1617 | if (isUploading) { |
| 1618 | showToast("Upload already in progress", Toasts.Type.MESSAGE); |
| 1619 | return; |
| 1620 | } |
| 1621 | |
| 1622 | if (!isConfigured()) { |
| 1623 | showToast("Please configure BigFileUpload settings first", Toasts.Type.FAILURE); |
| 1624 | return; |
| 1625 | } |
| 1626 | |
| 1627 | if (!files.length) return; |
| 1628 | |
| 1629 | const uploadFiles = files.filter(file => Boolean(file) && isFileTypeAllowed(file)); |
| 1630 | if (!uploadFiles.length) return; |
| 1631 | |
| 1632 | isUploading = true; |
| 1633 | cancelRequested = false; |
| 1634 | |
| 1635 | try { |
| 1636 | for (let i = 0; i < uploadFiles.length; i++) { |
| 1637 | const file = uploadFiles[i]; |
| 1638 | const current = i + 1; |
| 1639 | const suffix = uploadFiles.length > 1 ? ` (${current}/${uploadFiles.length})` : ""; |
| 1640 | |
| 1641 | setUploadState({ |
| 1642 | phase: "preparing", |
| 1643 | fileName: file.name, |
| 1644 | currentService: null, |
| 1645 | currentServiceLabel: "", |
| 1646 | attempt: 0, |
| 1647 | totalAttempts: 0, |
| 1648 | percent: 2, |
| 1649 | status: `Preparing ${file.name}${suffix}...`, |
| 1650 | canCancel: true |
| 1651 | }); |
| 1652 | |
| 1653 | await uploadPreparedBlob(file, undefined, forceSend); |
| 1654 | } |
| 1655 | } catch (error) { |
| 1656 | const message = error instanceof Error ? error.message : "Unknown error"; |
| 1657 | if (isUploadCancelledError(error)) { |
| 1658 | showToast("Upload cancelled", Toasts.Type.MESSAGE); |
| 1659 | setUploadState({ phase: "cancelled", status: "Upload cancelled.", canCancel: false, percent: 0 }); |
| 1660 | } else { |
| 1661 | showToast(`Upload failed: ${message}`, Toasts.Type.FAILURE); |
| 1662 | logger.error("Manual upload error", error); |
| 1663 | setUploadState({ phase: "failed", status: `Upload failed: ${message}`, canCancel: false, percent: 0 }); |
| 1664 | } |
| 1665 | } finally { |
| 1666 | isUploading = false; |
| 1667 | activeAbortController = null; |
| 1668 | activeXhr = null; |
| 1669 | setTimeout(() => resetUploadState(), 1800); |
| 1670 | } |
| 1671 | } |
no test coverage detected