Filter meteo warnings by local county

This commit is contained in:
zv
2026-06-12 19:16:57 +02:00
parent 5eaaff963f
commit 487a480bbd
19 changed files with 154 additions and 30 deletions

View File

@@ -2,6 +2,7 @@ import { NextResponse } from "next/server";
import { fetchMeteoWarnings } from "@/lib/server-warnings";
import { getPushSubscriptions, hasSentWarning, markWarningSent, pruneSentWarnings, removePushSubscription } from "@/lib/push-store";
import { isWebPushConfigured, sendWarningNotification } from "@/lib/push-service";
import { warningMatchesCounty } from "@/lib/warning-regions";
import type { WeatherWarning } from "@/types/imgw";
export const runtime = "nodejs";
@@ -44,7 +45,9 @@ export async function GET(request: Request) {
pruneSentWarnings(activeWarningIds);
for (const subscription of subscriptions) {
const matchingWarnings = warnings.filter((warning) => warning.provinces.includes(subscription.province));
const matchingWarnings = warnings.filter((warning) => (
subscription.countyTeryt ? warningMatchesCounty(warning, subscription.countyTeryt) : warning.provinces.includes(subscription.province)
));
for (const warning of matchingWarnings) {
if (hasSentWarning(subscription.endpoint, warning.id)) {
skipped += 1;

View File

@@ -59,6 +59,7 @@ export async function GET(request: Request) {
forecast,
warnings,
province: subscription.province,
countyTeryt: subscription.countyTeryt,
locationName: subscription.locationName ?? "wtr.",
language: subscription.language,
now,

View File

@@ -30,6 +30,7 @@ export async function POST(request: Request) {
latitude?: unknown;
longitude?: unknown;
locationName?: unknown;
countyTeryt?: unknown;
} | null;
const subscription = body?.subscription;
const province = normalizeProvinceName(typeof body?.province === "string" ? body.province : null);
@@ -50,6 +51,7 @@ export async function POST(request: Request) {
latitude: typeof body?.latitude === "number" && Number.isFinite(body.latitude) ? body.latitude : null,
longitude: typeof body?.longitude === "number" && Number.isFinite(body.longitude) ? body.longitude : null,
locationName: typeof body?.locationName === "string" && body.locationName.trim() ? body.locationName.trim().slice(0, 80) : null,
countyTeryt: typeof body?.countyTeryt === "string" && /^\d{4}$/.test(body.countyTeryt) ? body.countyTeryt : null,
createdAt: now,
updatedAt: now,
});