(
_: IpcMainInvokeEvent,
fileBuffer: ArrayBuffer,
filename: string,
token?: string
)
| 238 | } |
| 239 | |
| 240 | export async function uploadToGofile( |
| 241 | _: IpcMainInvokeEvent, |
| 242 | fileBuffer: ArrayBuffer, |
| 243 | filename: string, |
| 244 | token?: string |
| 245 | ): Promise<NativeUploadResult> { |
| 246 | try { |
| 247 | const fields: Record<string, string> = {}; |
| 248 | if (token?.trim()) fields.token = token.trim(); |
| 249 | const response = await multipartFetch("https://upload.gofile.io/uploadfile", fields, "file", fileBuffer, filename); |
| 250 | |
| 251 | if (!response.ok) { |
| 252 | const errorText = await response.text(); |
| 253 | return { success: false, error: `Upload failed: ${response.status} ${errorText}` }; |
| 254 | } |
| 255 | |
| 256 | const data = await response.json() as { |
| 257 | status?: string; |
| 258 | error?: string; |
| 259 | data?: { downloadPage?: string; code?: string; }; |
| 260 | }; |
| 261 | |
| 262 | if (data.status !== "ok") { |
| 263 | return { success: false, error: data.error || "Upload failed" }; |
| 264 | } |
| 265 | |
| 266 | const url = data.data?.downloadPage || (data.data?.code ? `https://gofile.io/d/${data.data.code}` : ""); |
| 267 | if (!url) { |
| 268 | return { success: false, error: "No URL returned from upload" }; |
| 269 | } |
| 270 | |
| 271 | return { success: true, url }; |
| 272 | } catch (e) { |
| 273 | return { success: false, error: e instanceof Error ? e.message : "Unknown error" }; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | export async function uploadToTmpfiles( |
| 278 | _: IpcMainInvokeEvent, |
nothing calls this directly
no test coverage detected