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();