first commit
This commit is contained in:
21
frontend/src/lib/api.ts
Normal file
21
frontend/src/lib/api.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import type { DashboardSnapshot } from '@/types'
|
||||
|
||||
const envBaseUrl = import.meta.env.VITE_API_BASE_URL as string | undefined
|
||||
|
||||
export const API_BASE = (envBaseUrl?.trim() || 'http://127.0.0.1:8001').replace(/\/$/, '')
|
||||
|
||||
async function fetchJson<T>(path: string): Promise<T> {
|
||||
const response = await fetch(`${API_BASE}${path}`)
|
||||
if (!response.ok) {
|
||||
throw new Error(`请求失败: ${response.status} ${response.statusText}`)
|
||||
}
|
||||
return response.json() as Promise<T>
|
||||
}
|
||||
|
||||
export function fetchDashboardSnapshot() {
|
||||
return fetchJson<DashboardSnapshot>('/api/dashboard/')
|
||||
}
|
||||
|
||||
export function buildVideoFrameUrl(frameKey: number) {
|
||||
return `${API_BASE}/api/video/frame/?frame=${frameKey}&t=${Date.now()}`
|
||||
}
|
||||
Reference in New Issue
Block a user