(fileBlob: Blob, filename: string)
| 667 | } |
| 668 | |
| 669 | async function uploadToCatbox(fileBlob: Blob, filename: string): Promise<string> { |
| 670 | const { catboxUserhash } = settings.store; |
| 671 | |
| 672 | if (Native) { |
| 673 | const result = await Native.uploadToCatbox(await fileBlob.arrayBuffer(), filename, catboxUserhash || undefined); |
| 674 | if (!result.success || !result.url) throw new Error(result.error || "No URL returned from upload"); |
| 675 | return result.url; |
| 676 | } |
| 677 | |
| 678 | const formData = new FormData(); |
| 679 | formData.append("reqtype", "fileupload"); |
| 680 | if (catboxUserhash) formData.append("userhash", catboxUserhash); |
| 681 | formData.append("fileToUpload", fileBlob, filename); |
| 682 | |
| 683 | const response = await uploadRequestWithTimeout("https://catbox.moe/user/api.php", { |
| 684 | method: "POST", |
| 685 | body: formData |
| 686 | }); |
| 687 | |
| 688 | if (!response.ok) throw new Error(`Upload failed: ${response.status} ${await response.text()}`); |
| 689 | const text = (await response.text()).trim(); |
| 690 | if (!text) throw new Error("No URL returned from upload"); |
| 691 | return text; |
| 692 | } |
| 693 | |
| 694 | async function uploadTo0x0(fileBlob: Blob, filename: string): Promise<string> { |
| 695 | if (!Native) { |
no test coverage detected