(url: string)
| 1521 | } |
| 1522 | |
| 1523 | export async function uploadFile(url: string): Promise<void> { |
| 1524 | if (isUploading) { |
| 1525 | showToast("Upload already in progress", Toasts.Type.MESSAGE); |
| 1526 | return; |
| 1527 | } |
| 1528 | |
| 1529 | if (!isConfigured()) { |
| 1530 | showToast("Please configure BigFileUpload settings first", Toasts.Type.FAILURE); |
| 1531 | return; |
| 1532 | } |
| 1533 | |
| 1534 | isUploading = true; |
| 1535 | cancelRequested = false; |
| 1536 | setUploadState({ |
| 1537 | phase: "preparing", |
| 1538 | fileName: "", |
| 1539 | currentService: null, |
| 1540 | currentServiceLabel: "", |
| 1541 | attempt: 0, |
| 1542 | totalAttempts: 0, |
| 1543 | percent: 1, |
| 1544 | status: "Preparing upload...", |
| 1545 | canCancel: true |
| 1546 | }); |
| 1547 | |
| 1548 | try { |
| 1549 | let fetchUrl = url; |
| 1550 | if (url.includes("/stickers/") && url.includes("passthrough=false")) { |
| 1551 | fetchUrl = url.replace("passthrough=false", "passthrough=true"); |
| 1552 | } |
| 1553 | |
| 1554 | let blob: Blob; |
| 1555 | let contentType = ""; |
| 1556 | |
| 1557 | if (Native) { |
| 1558 | const res = await Native.fetchFile(fetchUrl, getUploadTimeoutMs()); |
| 1559 | if (res.success && res.data) { |
| 1560 | contentType = res.contentType || ""; |
| 1561 | blob = new Blob([res.data], { type: contentType }); |
| 1562 | } else { |
| 1563 | const response = await fetch(fetchUrl); |
| 1564 | if (!response.ok) { |
| 1565 | throw new Error(`Failed to fetch file: ${response.status}`); |
| 1566 | } |
| 1567 | contentType = response.headers.get("content-type") || ""; |
| 1568 | blob = await response.blob(); |
| 1569 | } |
| 1570 | } else { |
| 1571 | const response = await fetchWithTimeout(fetchUrl, { |
| 1572 | method: "GET" |
| 1573 | }); |
| 1574 | if (!response.ok) { |
| 1575 | throw new Error(`Failed to fetch file: ${response.status}`); |
| 1576 | } |
| 1577 | contentType = response.headers.get("content-type") || ""; |
| 1578 | blob = await response.blob(); |
| 1579 | } |
| 1580 |
no test coverage detected