(
_: IpcMainInvokeEvent,
ocsUrl: string,
headers: Record<string, string>,
body: string
)
| 484 | } |
| 485 | |
| 486 | export async function createWebdavShare( |
| 487 | _: IpcMainInvokeEvent, |
| 488 | ocsUrl: string, |
| 489 | headers: Record<string, string>, |
| 490 | body: string |
| 491 | ): Promise<NativeUploadResult> { |
| 492 | if (!isValidHttpsUrl(ocsUrl)) { |
| 493 | return { success: false, error: "Invalid or non-HTTPS share endpoint URL" }; |
| 494 | } |
| 495 | |
| 496 | try { |
| 497 | const response = await fetch(ocsUrl, { |
| 498 | method: "POST", |
| 499 | headers, |
| 500 | body |
| 501 | }); |
| 502 | |
| 503 | const text = await response.text(); |
| 504 | |
| 505 | if (!response.ok) { |
| 506 | return { success: false, error: `Share creation failed: ${response.status} ${text.slice(0, 200)}` }; |
| 507 | } |
| 508 | |
| 509 | let data: { ocs?: { data?: { token?: string; }; }; }; |
| 510 | try { |
| 511 | data = JSON.parse(text); |
| 512 | } catch { |
| 513 | return { success: false, error: `Invalid share response: ${text.slice(0, 200)}` }; |
| 514 | } |
| 515 | |
| 516 | const token = data?.ocs?.data?.token; |
| 517 | if (!token) { |
| 518 | return { success: false, error: "No share token in server response" }; |
| 519 | } |
| 520 | |
| 521 | return { success: true, url: token }; |
| 522 | } catch (e) { |
| 523 | return { success: false, error: e instanceof Error ? e.message : "Unknown error" }; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | export async function fetchFile( |
| 528 | _: IpcMainInvokeEvent, |
nothing calls this directly
no test coverage detected