(fileBlob: Blob, filename: string)
| 776 | } |
| 777 | |
| 778 | async function uploadToTmpfiles(fileBlob: Blob, filename: string): Promise<string> { |
| 779 | if (Native) { |
| 780 | const result = await Native.uploadToTmpfiles(await fileBlob.arrayBuffer(), filename); |
| 781 | if (!result.success || !result.url) throw new Error(result.error || "No URL returned from upload"); |
| 782 | return result.url; |
| 783 | } |
| 784 | |
| 785 | const formData = new FormData(); |
| 786 | formData.append("file", fileBlob, filename); |
| 787 | |
| 788 | const uploadUrl = "https://tmpfiles.org/api/v1/upload"; |
| 789 | const response = await uploadRequestWithTimeout(uploadUrl, { |
| 790 | method: "POST", |
| 791 | body: formData |
| 792 | }); |
| 793 | |
| 794 | if (!response.ok) { |
| 795 | throw new Error(`Upload failed: ${response.status} ${await response.text()}`); |
| 796 | } |
| 797 | |
| 798 | const data = await response.json() as { status?: string; data?: { url?: string; }; }; |
| 799 | const url = data.data?.url; |
| 800 | if (!url || data.status !== "success") { |
| 801 | throw new Error("No URL returned from upload"); |
| 802 | } |
| 803 | |
| 804 | return url.includes("tmpfiles.org/") && !url.includes("/dl/") |
| 805 | ? url.replace(/tmpfiles\.org\/(\d+)/, "tmpfiles.org/dl/$1") |
| 806 | : url; |
| 807 | } |
| 808 | |
| 809 | async function uploadToBuzzheavier(fileBlob: Blob, filename: string): Promise<string> { |
| 810 | if (Native) { |
no test coverage detected