(fileBlob: Blob, filename: string)
| 894 | } |
| 895 | |
| 896 | async function uploadToPixelVault(fileBlob: Blob, filename: string): Promise<string> { |
| 897 | const { pixelVaultKey } = settings.store as { pixelVaultKey?: string; }; |
| 898 | |
| 899 | if (!pixelVaultKey?.trim()) { |
| 900 | throw new Error("PixelVault upload key is required"); |
| 901 | } |
| 902 | |
| 903 | if (Native) { |
| 904 | const result = await Native.uploadToPixelVault(await fileBlob.arrayBuffer(), filename, pixelVaultKey.trim()); |
| 905 | |
| 906 | if (!result.success) { |
| 907 | throw new Error(result.error || "Upload failed"); |
| 908 | } |
| 909 | |
| 910 | if (!result.url) { |
| 911 | throw new Error("No URL returned from upload"); |
| 912 | } |
| 913 | |
| 914 | return result.url; |
| 915 | } |
| 916 | |
| 917 | const formData = new FormData(); |
| 918 | formData.append("file", fileBlob, filename); |
| 919 | |
| 920 | const response = await uploadRequestWithTimeout("https://pixelvault.co/", { |
| 921 | method: "POST", |
| 922 | headers: { |
| 923 | Authorization: pixelVaultKey.trim() |
| 924 | }, |
| 925 | body: formData |
| 926 | }); |
| 927 | |
| 928 | const text = await response.text(); |
| 929 | let data: { resource?: string; url?: string; } | null = null; |
| 930 | |
| 931 | try { |
| 932 | data = text ? JSON.parse(text) : null; |
| 933 | } catch { |
| 934 | data = null; |
| 935 | } |
| 936 | |
| 937 | if (!response.ok) { |
| 938 | throw new Error(`Upload failed: ${response.status} ${text}`); |
| 939 | } |
| 940 | |
| 941 | const url = data?.resource || data?.url || text.trim(); |
| 942 | if (!url) { |
| 943 | throw new Error("No URL returned from upload"); |
| 944 | } |
| 945 | |
| 946 | return url; |
| 947 | } |
| 948 | |
| 949 | async function uploadToPixelDrain(fileBlob: Blob, filename: string): Promise<string> { |
| 950 | const { pixelDrainKey } = settings.store as { pixelDrainKey?: string; }; |
no test coverage detected