Refactor: enhance API response schemas for pagination; update environment variables for Supabase and Vision API; improve Vite configuration for proxy routing

This commit is contained in:
salirezav
2025-08-12 13:48:17 -04:00
parent 7a939920fa
commit 62dd0d162b
9 changed files with 57 additions and 35 deletions

View File

@@ -15,9 +15,8 @@ import {
} from '../types';
import { performanceMonitor } from '../utils/performanceMonitor';
// Configuration - Use environment variable or default to vision container
// The API is accessible at localhost:8000 in the current setup
const API_BASE_URL = import.meta.env.VITE_VISION_API_URL || 'http://localhost:8000';
// Configuration - Prefer env var; default to relative "/api" so Vite proxy can route to the API container
const API_BASE_URL = import.meta.env.VITE_VISION_API_URL || '/api';
/**
* Custom error class for video API errors

View File

@@ -1,8 +1,12 @@
import { createClient } from '@supabase/supabase-js'
// Local development configuration
const supabaseUrl = 'http://127.0.0.1:54321'
const supabaseAnonKey = '[REDACTED]'
// Supabase configuration from environment (Vite)
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY
if (!supabaseUrl || !supabaseAnonKey) {
throw new Error('Supabase is not configured. Please set VITE_SUPABASE_URL and VITE_SUPABASE_ANON_KEY in your environment (.env)')
}
export const supabase = createClient(supabaseUrl, supabaseAnonKey)

View File

@@ -1,7 +1,6 @@
// Vision System API Client
// Base URL for the vision system API - Use environment variable or default to vision container
// The API is accessible at localhost:8000 in the current setup
const VISION_API_BASE_URL = import.meta.env.VITE_VISION_API_URL || 'http://localhost:8000'
// Base URL for the vision system API - Prefer env var; default to relative "/api" so Vite proxy can route to the API container
const VISION_API_BASE_URL = import.meta.env.VITE_VISION_API_URL || '/api'
// Types based on the API documentation
export interface SystemStatus {
@@ -290,7 +289,7 @@ class VisionApiClient {
private async request<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
const url = `${this.baseUrl}${endpoint}`
const response = await fetch(url, {
headers: {
'Content-Type': 'application/json',
@@ -424,8 +423,8 @@ class VisionApiClient {
} catch (error: any) {
// If the error is related to missing auto-recording fields, try to handle it gracefully
if (error.message?.includes('auto_start_recording_enabled') ||
error.message?.includes('auto_recording_max_retries') ||
error.message?.includes('auto_recording_retry_delay_seconds')) {
error.message?.includes('auto_recording_max_retries') ||
error.message?.includes('auto_recording_retry_delay_seconds')) {
// Try to get the raw camera data and add default auto-recording fields
try {
@@ -540,7 +539,7 @@ export const formatDuration = (seconds: number): string => {
const hours = Math.floor(seconds / 3600)
const minutes = Math.floor((seconds % 3600) / 60)
const secs = Math.floor(seconds % 60)
if (hours > 0) {
return `${hours}h ${minutes}m ${secs}s`
} else if (minutes > 0) {
@@ -554,7 +553,7 @@ export const formatUptime = (seconds: number): string => {
const days = Math.floor(seconds / 86400)
const hours = Math.floor((seconds % 86400) / 3600)
const minutes = Math.floor((seconds % 3600) / 60)
if (days > 0) {
return `${days}d ${hours}h ${minutes}m`
} else if (hours > 0) {

View File

@@ -3,6 +3,7 @@
interface ImportMetaEnv {
readonly VITE_SUPABASE_URL: string;
readonly VITE_SUPABASE_ANON_KEY: string;
readonly VITE_VISION_API_URL?: string; // optional; defaults to "/api" via vite proxy
}
interface ImportMeta {