From 3f25ea11249953148750ee16d1deaf5706a819b7 Mon Sep 17 00:00:00 2001 From: Zac Gaetano Date: Tue, 7 Apr 2026 22:05:44 -0400 Subject: [PATCH] Phase 2: services/web-ui/public/js/api.js --- services/web-ui/public/js/api.js | 99 ++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/services/web-ui/public/js/api.js b/services/web-ui/public/js/api.js index ec002e7..d5747e9 100644 --- a/services/web-ui/public/js/api.js +++ b/services/web-ui/public/js/api.js @@ -346,3 +346,102 @@ function throttle(func, limit) { } }; } + +// ============================================================ +// UPLOAD API CALLS +// ============================================================ + +/** + * Initialize a multipart upload + */ +async function initUpload(data) { + return api('/upload/init', { method: 'POST', body: JSON.stringify(data) }); +} + +/** + * Complete a multipart upload + */ +async function completeUpload(data) { + return api('/upload/complete', { method: 'POST', body: JSON.stringify(data) }); +} + +/** + * Abort an ongoing upload + */ +async function abortUpload(data) { + return api('/upload/abort', { method: 'POST', body: JSON.stringify(data) }); +} + +/** + * Upload a file part (FormData, no JSON content-type) + */ +async function uploadPart(formData) { + try { + const response = await fetch('/api/v1/upload/part', { method: 'POST', body: formData }); + if (!response.ok) throw new Error(`Upload part failed: ${response.status}`); + const data = await response.json(); + return { success: true, data }; + } catch (error) { + return { success: false, error: error.message }; + } +} + +/** + * Simple upload for small files (under 50MB) + */ +async function simpleUpload(formData) { + try { + const response = await fetch('/api/v1/upload/simple', { method: 'POST', body: formData }); + if (!response.ok) throw new Error(`Upload failed: ${response.status}`); + const data = await response.json(); + return { success: true, data }; + } catch (error) { + return { success: false, error: error.message }; + } +} + +// ============================================================ +// RECORDER API CALLS +// ============================================================ + +/** + * Get all recorder instances + */ +async function getRecorders() { + return api('/recorders'); +} + +/** + * Create a new recorder instance + */ +async function createRecorder(data) { + return api('/recorders', { method: 'POST', body: JSON.stringify(data) }); +} + +/** + * Start a recorder by ID + */ +async function startRecorder(id) { + return api(`/recorders/${id}/start`, { method: 'POST' }); +} + +/** + * Stop a recorder by ID + */ +async function stopRecorder(id) { + return api(`/recorders/${id}/stop`, { method: 'POST' }); +} + +/** + * Delete a recorder by ID + */ +async function deleteRecorder(id) { + return api(`/recorders/${id}`, { method: 'DELETE' }); +} + +/** + * Get live status for a recorder + */ +async function getRecorderStatus(id) { + return api(`/recorders/${id}/status`); +}