import useSWR from "swr"; import { FiHardDrive } from "react-icons/fi"; import { BiError } from "react-icons/bi"; import { useTranslation } from "next-i18next"; import UsageBar from "./usage-bar"; export default function Disk({ options, expanded, backend }) { const { t } = useTranslation(); const { data, error } = useSWR(`/api/widgets/${backend || 'resources'}?type=disk&target=${options.disk}`, { refreshInterval: 1500, }); if (error || data?.error) { return (
{t("widget.api_error")}
); } if (!data) { return (
-
{t("resources.free")}
{expanded && (
-
{t("resources.total")}
)}
); } const percent = Math.round((data.drive.usedGb / data.drive.totalGb) * 100); return (
{t("common.bytes", { value: data.drive.freeGb * 1024 * 1024 * 1024 })}
{t("resources.free")}
{expanded && (
{t("common.bytes", { value: data.drive.totalGb * 1024 * 1024 * 1024 })}
{t("resources.total")}
)}
); }