Fix upload by using API client with proper authentication

This commit is contained in:
Patrick Britton 2026-02-16 10:26:13 -06:00
parent 2622d0fb79
commit b04d10853b
2 changed files with 26 additions and 17 deletions

View file

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

View file

@ -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<string, string> = {};
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();