Spaces:
Running
Running
| // frontend/lib/api.ts | |
| import type { DetectionResponse } from '@/types/detection' | |
| const BASE_URL = '/api' | |
| async function _post(endpoint: string, file: File): Promise<DetectionResponse> { | |
| const form = new FormData() | |
| form.append('file', file) | |
| const res = await fetch(`${BASE_URL}${endpoint}`, { | |
| method: 'POST', | |
| body: form, | |
| }) | |
| if (!res.ok) { | |
| const err = await res.text() | |
| throw new Error(`Detection failed (${res.status}): ${err}`) | |
| } | |
| return res.json() | |
| } | |
| export const detectImage = (file: File) => _post('/detect/image', file) | |
| export const detectVideo = (file: File) => _post('/detect/video', file) | |
| export async function healthCheck(): Promise<{ status: string; version?: string }> { | |
| const res = await fetch(`${BASE_URL}/health`) | |
| if (!res.ok) throw new Error(`Health check failed: ${res.status}`) | |
| return res.json() | |
| } | |