(fileBlob: Blob, filename: string)
| 947 | } |
| 948 | |
| 949 | async function uploadToPixelDrain(fileBlob: Blob, filename: string): Promise<string> { |
| 950 | const { pixelDrainKey } = settings.store as { pixelDrainKey?: string; }; |
| 951 | |
| 952 | if (Native) { |
| 953 | const result = await Native.uploadToPixelDrain(await fileBlob.arrayBuffer(), filename, pixelDrainKey?.trim() || undefined); |
| 954 | if (!result.success || !result.url) throw new Error(result.error || "No URL returned from upload"); |
| 955 | return result.url; |
| 956 | } |
| 957 | |
| 958 | const headers: Record<string, string> = {}; |
| 959 | if (pixelDrainKey?.trim()) { |
| 960 | headers.Authorization = `Basic ${btoa(`:${pixelDrainKey.trim()}`)}`; |
| 961 | } |
| 962 | |
| 963 | const response = await uploadRequestWithTimeout(`https://pixeldrain.com/api/file/${encodeURIComponent(filename)}`, { |
| 964 | method: "PUT", |
| 965 | headers, |
| 966 | body: fileBlob |
| 967 | }); |
| 968 | |
| 969 | const text = await response.text(); |
| 970 | let data: { id?: string; success?: boolean; message?: string; } | null = null; |
| 971 | try { |
| 972 | data = text ? JSON.parse(text) : null; |
| 973 | } catch { |
| 974 | data = null; |
| 975 | } |
| 976 | |
| 977 | if (!response.ok) { |
| 978 | throw new Error(data?.message || `Upload failed: ${response.status} ${text}`); |
| 979 | } |
| 980 | |
| 981 | if (!data?.id) { |
| 982 | throw new Error(data?.message || "No URL returned from upload"); |
| 983 | } |
| 984 | |
| 985 | return `https://pixeldrain.com/u/${data.id}`; |
| 986 | } |
| 987 | |
| 988 | function buildWebdavAuthHeader(): string | null { |
| 989 | const { webdavUsername, webdavPassword } = settings.store as { |
no test coverage detected