From b04d10853b29161618c9a3fa49dd46759db57c4d Mon Sep 17 00:00:00 2001 From: Patrick Britton Date: Mon, 16 Feb 2026 10:26:13 -0600 Subject: [PATCH] Fix upload by using API client with proper authentication --- admin/src/app/ai-moderation/page.tsx | 19 ++----------------- admin/src/lib/api.ts | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/admin/src/app/ai-moderation/page.tsx b/admin/src/app/ai-moderation/page.tsx index 46bd465..4362bb9 100644 --- a/admin/src/app/ai-moderation/page.tsx +++ b/admin/src/app/ai-moderation/page.tsx @@ -146,26 +146,11 @@ export default function AIModerationPage() { const handleFileUpload = async (file: File) => { setUploading(true); try { - // Create FormData and upload to get a URL - const formData = new FormData(); - formData.append('file', file); - - const response = await fetch('/api/v1/admin/upload-test-image', { - method: 'POST', - body: formData, - headers: { - 'Authorization': `Bearer ${localStorage.getItem('token') || ''}`, - }, - }); - - if (!response.ok) { - throw new Error('Upload failed'); - } - - const result = await response.json(); + const result = await api.uploadTestImage(file); setTestInput(result.url); setUploadedFile(file); } catch (e: any) { + console.error('Upload error:', e); alert('Upload failed: ' + e.message); } finally { setUploading(false); diff --git a/admin/src/lib/api.ts b/admin/src/lib/api.ts index 8e408a1..3c6b9bb 100644 --- a/admin/src/lib/api.ts +++ b/admin/src/lib/api.ts @@ -438,6 +438,30 @@ class ApiClient { }); } + async uploadTestImage(file: File) { + const formData = new FormData(); + formData.append('file', file); + + const token = this.getToken(); + const headers: Record = {}; + if (token) { + headers['Authorization'] = `Bearer ${token}`; + } + + const response = await fetch(`${API_BASE}/api/v1/admin/upload-test-image`, { + method: 'POST', + body: formData, + headers, + }); + + if (!response.ok) { + const errorText = await response.text(); + throw new Error(`Upload failed: ${response.status} - ${errorText}`); + } + + return response.json(); + } + // AI Moderation Audit Log async getAIModerationLog(params: { limit?: number; offset?: number; decision?: string; content_type?: string; search?: string; feedback?: string } = {}) { const qs = new URLSearchParams();