(
_: IpcMainInvokeEvent,
fileBuffer: ArrayBuffer,
filename: string,
userhash?: string
)
| 186 | } |
| 187 | |
| 188 | export async function uploadToCatbox( |
| 189 | _: IpcMainInvokeEvent, |
| 190 | fileBuffer: ArrayBuffer, |
| 191 | filename: string, |
| 192 | userhash?: string |
| 193 | ): Promise<NativeUploadResult> { |
| 194 | try { |
| 195 | const fields: Record<string, string> = { reqtype: "fileupload" }; |
| 196 | if (userhash) fields.userhash = userhash; |
| 197 | const response = await multipartFetch("https://catbox.moe/user/api.php", fields, "fileToUpload", fileBuffer, filename); |
| 198 | |
| 199 | if (!response.ok) { |
| 200 | const errorText = await response.text(); |
| 201 | return { success: false, error: `Upload failed: ${response.status} ${errorText}` }; |
| 202 | } |
| 203 | |
| 204 | const text = (await response.text()).trim(); |
| 205 | if (!text) { |
| 206 | return { success: false, error: "No URL returned from upload" }; |
| 207 | } |
| 208 | |
| 209 | return { success: true, url: text }; |
| 210 | } catch (e) { |
| 211 | return { success: false, error: e instanceof Error ? e.message : "Unknown error" }; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | export async function uploadToLitterbox( |
| 216 | _: IpcMainInvokeEvent, |
nothing calls this directly
no test coverage detected