(fileBlob: Blob, filename: string)
| 736 | } |
| 737 | |
| 738 | async function uploadToGofile(fileBlob: Blob, filename: string): Promise<string> { |
| 739 | const { gofileToken } = settings.store as { gofileToken?: string; }; |
| 740 | |
| 741 | if (Native) { |
| 742 | const result = await Native.uploadToGofile(await fileBlob.arrayBuffer(), filename, gofileToken || undefined); |
| 743 | if (!result.success || !result.url) throw new Error(result.error || "No URL returned from upload"); |
| 744 | return result.url; |
| 745 | } |
| 746 | |
| 747 | const formData = new FormData(); |
| 748 | if (gofileToken?.trim()) { |
| 749 | formData.append("token", gofileToken.trim()); |
| 750 | } |
| 751 | formData.append("file", fileBlob, filename); |
| 752 | |
| 753 | const uploadUrl = "https://upload.gofile.io/uploadfile"; |
| 754 | const response = await uploadRequestWithTimeout(uploadUrl, { |
| 755 | method: "POST", |
| 756 | body: formData |
| 757 | }); |
| 758 | |
| 759 | if (!response.ok) { |
| 760 | throw new Error(`Upload failed: ${response.status} ${await response.text()}`); |
| 761 | } |
| 762 | |
| 763 | const data = await response.json() as { |
| 764 | status?: string; |
| 765 | error?: string; |
| 766 | data?: { downloadPage?: string; code?: string; }; |
| 767 | }; |
| 768 | |
| 769 | if (data.status !== "ok") { |
| 770 | throw new Error(data.error || "Upload failed"); |
| 771 | } |
| 772 | |
| 773 | const url = data.data?.downloadPage || (data.data?.code ? `https://gofile.io/d/${data.data.code}` : ""); |
| 774 | if (!url) throw new Error("No URL returned from upload"); |
| 775 | return url; |
| 776 | } |
| 777 | |
| 778 | async function uploadToTmpfiles(fileBlob: Blob, filename: string): Promise<string> { |
| 779 | if (Native) { |
no test coverage detected