MCPcopy Create free account
hub / github.com/ScattrdBlade/bigFileUpload / uploadFile

Function uploadFile

utils/upload.ts:1523–1602  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

1521}
1522
1523export 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

Callers 2

messageContextMenuPatchFunction · 0.90
imageContextMenuPatchFunction · 0.90

Calls 7

isConfiguredFunction · 0.85
setUploadStateFunction · 0.85
getUploadTimeoutMsFunction · 0.85
fetchWithTimeoutFunction · 0.85
uploadPreparedBlobFunction · 0.85
isUploadCancelledErrorFunction · 0.85
resetUploadStateFunction · 0.85

Tested by

no test coverage detected