(fileBlob: Blob, filename: string)
| 807 | } |
| 808 | |
| 809 | async function uploadToBuzzheavier(fileBlob: Blob, filename: string): Promise<string> { |
| 810 | if (Native) { |
| 811 | const result = await Native.uploadToBuzzheavier(await fileBlob.arrayBuffer(), filename); |
| 812 | if (!result.success || !result.url) throw new Error(result.error || "No URL returned from upload"); |
| 813 | return result.url; |
| 814 | } |
| 815 | |
| 816 | const uploadUrl = `https://w.buzzheavier.com/${encodeURIComponent(filename)}`; |
| 817 | const response = await uploadRequestWithTimeout(uploadUrl, { |
| 818 | method: "PUT", |
| 819 | body: fileBlob |
| 820 | }); |
| 821 | |
| 822 | const text = await response.text(); |
| 823 | if (!response.ok) { |
| 824 | throw new Error(`Upload failed: ${response.status} ${text}`); |
| 825 | } |
| 826 | |
| 827 | try { |
| 828 | const data = JSON.parse(text) as { code?: number; data?: { id?: string; }; }; |
| 829 | const id = data.data?.id; |
| 830 | if (data.code === 201 && id) { |
| 831 | return `https://buzzheavier.com/${id}`; |
| 832 | } |
| 833 | } catch { |
| 834 | } |
| 835 | |
| 836 | const fallback = text.trim(); |
| 837 | if (!fallback) throw new Error("No URL returned from upload"); |
| 838 | return fallback; |
| 839 | } |
| 840 | |
| 841 | async function uploadToTempSh(fileBlob: Blob, filename: string): Promise<string> { |
| 842 | if (Native) { |
no test coverage detected