fix(weather): handle disabled external connections (#6780)

This commit is contained in:
Thomas authored and GitHub committed 2026-09-06 15:35:06 +02:00
1 parent 50a3bcce69
commit 724dee55c5
5 files changed
+20 -6

No files matched your search

+3
View File
@@ -1,5 +1,6 @@
import { z } from "zod/v4";
import { env } from "@homarr/common/env";
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
import { withTimeoutAsync } from "@homarr/core/infrastructure/http/timeout";
@@ -37,6 +38,8 @@ export const locationRouter = createTRPCRouter({
.input(locationSearchCityInput)
.output(locationSearchCityOutput)
.query(async ({ input }) => {
if (env.NO_EXTERNAL_CONNECTION) return { results: [] };
const url = new URL("https://geocoding-api.open-meteo.com/v1/search");
url.searchParams.set("name", input.query);
const res = await withTimeoutAsync(async (signal) => {
+1
View File
@@ -3125,6 +3125,7 @@
}
},
"currentWindSpeed": "{currentWindSpeed} {unit}",
"disabled": "Weather data is unavailable because outbound connections are disabled",
"dailyForecast": {
"sunrise": "Sunrise",
"sunset": "Sunset",
+12 -3
View File
@@ -1,10 +1,10 @@
"use client";
import { Box } from "@mantine/core";
import { Box, Center, Text } from "@mantine/core";
import { clientApi } from "@homarr/api/client";
import { useI18n } from "@homarr/translation/client";
import { WidgetEmptyState } from "../common/empty-state";
import { getUsableWidgetQueryData, isInitialWidgetQueryPending } from "../common/query-state";
import { WidgetQueryLoadingState } from "../common/query-state-indicator";
import type { WidgetComponentProps } from "../definition";
@@ -19,6 +19,7 @@ export default function WeatherWidget({
height,
displayMode,
}: WidgetComponentProps<"weather">) {
const t = useI18n("widget.weather");
const input = {
latitude: options.location.latitude,
longitude: options.location.longitude,
@@ -27,7 +28,15 @@ export default function WeatherWidget({
const weather = getUsableWidgetQueryData(weatherQuery);
if (isInitialWidgetQueryPending(weatherQuery)) return <WidgetQueryLoadingState />;
if (!weather) return <WidgetEmptyState />;
if (!weather) {
return (
<Center h="100%" w="100%" p="sm">
<Text c="dimmed" size="sm" ta="center">
{t("disabled")}
</Text>
</Center>
);
}
return (
<Box className={classes.weatherSurface} h="100%" w="100%" pos="relative">