diff --git a/AppImage/components/proxmox-dashboard.tsx b/AppImage/components/proxmox-dashboard.tsx index 4737717..0ab1c83 100644 --- a/AppImage/components/proxmox-dashboard.tsx +++ b/AppImage/components/proxmox-dashboard.tsx @@ -14,7 +14,7 @@ import { Settings } from "./settings" import { OnboardingCarousel } from "./onboarding-carousel" import { HealthStatusModal } from "./health-status-modal" import { ReleaseNotesModal, useVersionCheck } from "./release-notes-modal" -import { getApiUrl } from "../lib/api-config" +import { getApiUrl, fetchApi } from "../lib/api-config" import { RefreshCw, AlertTriangle, @@ -80,22 +80,8 @@ export function ProxmoxDashboard() { const { showReleaseNotes, setShowReleaseNotes } = useVersionCheck() const fetchSystemData = useCallback(async () => { - const apiUrl = getApiUrl("/api/system-info") - try { - const response = await fetch(apiUrl, { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - cache: "no-store", - }) - - if (!response.ok) { - throw new Error(`Server responded with status: ${response.status}`) - } - - const data: FlaskSystemInfo = await response.json() + const data: FlaskSystemInfo = await fetchApi("/api/system-info") const uptimeValue = data.uptime && typeof data.uptime === "string" && data.uptime.trim() !== "" ? data.uptime : "N/A" diff --git a/AppImage/components/storage-overview.tsx b/AppImage/components/storage-overview.tsx index f37192d..8c3724b 100644 --- a/AppImage/components/storage-overview.tsx +++ b/AppImage/components/storage-overview.tsx @@ -6,7 +6,7 @@ import { HardDrive, Database, AlertTriangle, CheckCircle2, XCircle, Square, Ther import { Badge } from "@/components/ui/badge" import { Progress } from "@/components/ui/progress" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog" -import { getApiUrl } from "../lib/api-config" +import { fetchApi } from "../lib/api-config" interface DiskInfo { name: string @@ -94,14 +94,11 @@ export function StorageOverview() { const fetchStorageData = async () => { try { - const [storageResponse, proxmoxResponse] = await Promise.all([ - fetch(getApiUrl("/api/storage")), - fetch(getApiUrl("/api/proxmox-storage")), + const [data, proxmoxData] = await Promise.all([ + fetchApi("/api/storage"), + fetchApi("/api/proxmox-storage"), ]) - const data = await storageResponse.json() - const proxmoxData = await proxmoxResponse.json() - setStorageData(data) setProxmoxStorage(proxmoxData) } catch (error) { diff --git a/AppImage/components/system-overview.tsx b/AppImage/components/system-overview.tsx index 43ad0d1..546b3c4 100644 --- a/AppImage/components/system-overview.tsx +++ b/AppImage/components/system-overview.tsx @@ -8,7 +8,7 @@ import { Cpu, MemoryStick, Thermometer, Server, Zap, AlertCircle, HardDrive, Net import { NodeMetricsCharts } from "./node-metrics-charts" import { NetworkTrafficChart } from "./network-traffic-chart" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select" -import { getApiUrl } from "../lib/api-config" +import { fetchApi } from "../lib/api-config" interface SystemData { cpu_usage: number @@ -98,21 +98,7 @@ interface ProxmoxStorageData { const fetchSystemData = async (): Promise => { try { - const apiUrl = getApiUrl("/api/system") - - const response = await fetch(apiUrl, { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - cache: "no-store", - }) - - if (!response.ok) { - throw new Error(`Flask server responded with status: ${response.status}`) - } - - const data = await response.json() + const data = await fetchApi("/api/system") return data } catch (error) { console.error("[v0] Failed to fetch system data:", error) @@ -122,21 +108,7 @@ const fetchSystemData = async (): Promise => { const fetchVMData = async (): Promise => { try { - const apiUrl = getApiUrl("/api/vms") - - const response = await fetch(apiUrl, { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - cache: "no-store", - }) - - if (!response.ok) { - throw new Error(`Flask server responded with status: ${response.status}`) - } - - const data = await response.json() + const data = await fetchApi("/api/vms") return Array.isArray(data) ? data : data.vms || [] } catch (error) { console.error("[v0] Failed to fetch VM data:", error) @@ -146,75 +118,30 @@ const fetchVMData = async (): Promise => { const fetchStorageData = async (): Promise => { try { - const apiUrl = getApiUrl("/api/storage/summary") - - const response = await fetch(apiUrl, { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - cache: "no-store", - }) - - if (!response.ok) { - console.log("[v0] Storage API not available (this is normal if not configured)") - return null - } - - const data = await response.json() + const data = await fetchApi("/api/storage/summary") return data } catch (error) { - console.log("[v0] Storage data unavailable:", error instanceof Error ? error.message : "Unknown error") + console.log("[v0] Storage API not available (this is normal if not configured)") return null } } const fetchNetworkData = async (): Promise => { try { - const apiUrl = getApiUrl("/api/network/summary") - - const response = await fetch(apiUrl, { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - cache: "no-store", - }) - - if (!response.ok) { - console.log("[v0] Network API not available (this is normal if not configured)") - return null - } - - const data = await response.json() + const data = await fetchApi("/api/network/summary") return data } catch (error) { - console.log("[v0] Network data unavailable:", error instanceof Error ? error.message : "Unknown error") + console.log("[v0] Network API not available (this is normal if not configured)") return null } } const fetchProxmoxStorageData = async (): Promise => { try { - const apiUrl = getApiUrl("/api/proxmox-storage") - - const response = await fetch(apiUrl, { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - cache: "no-store", - }) - - if (!response.ok) { - console.log("[v0] Proxmox storage API not available") - return null - } - - const data = await response.json() + const data = await fetchApi("/api/proxmox-storage") return data } catch (error) { - console.log("[v0] Proxmox storage data unavailable:", error instanceof Error ? error.message : "Unknown error") + console.log("[v0] Proxmox storage API not available") return null } }