import { useAuthStore } from '../store/authStore' export async function uploadCSV( topic_id: string, file: File, ): Promise<{ inserted: number }> { const token = useAuthStore.getState().accessToken const formData = new FormData() formData.append('file', file) formData.append('topic_id', topic_id) // Cannot use apiFetch here — browser must set Content-Type for multipart boundary const res = await fetch('/api/upload', { method: 'POST', headers: token ? { Authorization: `Bearer ${token}` } : {}, body: formData, credentials: 'include', }) if (!res.ok) { const err = await res.json() throw new Error(err.detail ?? 'Upload failed') } return res.json() }