From 774cbe4c9d3edf45c86f95e5ea613282d85a08d9 Mon Sep 17 00:00:00 2001 From: MacRimi Date: Thu, 13 Nov 2025 18:32:44 +0100 Subject: [PATCH] Update AppImage --- AppImage/components/metrics-dialog.tsx | 18 ++---------------- AppImage/types/hardware.ts | 8 +++++++- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/AppImage/components/metrics-dialog.tsx b/AppImage/components/metrics-dialog.tsx index c6f521a..ce201a6 100644 --- a/AppImage/components/metrics-dialog.tsx +++ b/AppImage/components/metrics-dialog.tsx @@ -5,7 +5,7 @@ import { Button } from "@/components/ui/button" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { ArrowLeft, Loader2 } from "lucide-react" import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend } from "recharts" -import { API_PORT } from "@/lib/api-config" +import { fetchApi } from "@/lib/api-config" interface MetricsViewProps { vmid: number @@ -119,21 +119,7 @@ export function MetricsView({ vmid, vmName, vmType, onBack }: MetricsViewProps) setError(null) try { - const { protocol, hostname, port } = window.location - const isStandardPort = port === "" || port === "80" || port === "443" - - const baseUrl = isStandardPort ? "" : `${protocol}//${hostname}:${API_PORT}` - - const apiUrl = `${baseUrl}/api/vms/${vmid}/metrics?timeframe=${timeframe}` - - const response = await fetch(apiUrl) - - if (!response.ok) { - const errorData = await response.json() - throw new Error(errorData.error || "Failed to fetch metrics") - } - - const result = await response.json() + const result = await fetchApi(`/api/vms/${vmid}/metrics?timeframe=${timeframe}`) const transformedData = result.data.map((item: any) => { const date = new Date(item.time * 1000) diff --git a/AppImage/types/hardware.ts b/AppImage/types/hardware.ts index c31de3c..90561ac 100644 --- a/AppImage/types/hardware.ts +++ b/AppImage/types/hardware.ts @@ -1,3 +1,5 @@ +import { fetchApi } from "@/lib/api-config" + export interface Temperature { name: string original_name?: string @@ -208,4 +210,8 @@ export interface HardwareData { ups?: UPS | UPS[] } -export const fetcher = (url: string) => fetch(url).then((res) => res.json()) +export const fetcher = async (url: string) => { + // Extract just the endpoint from the URL if it's a full URL + const endpoint = url.startsWith("http") ? new URL(url).pathname : url + return fetchApi(endpoint) +}