Fix upload by using API client with proper authentication
This commit is contained in:
parent
2622d0fb79
commit
b04d10853b
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue