fix(tides): fix stale locations in frontend and implement digraph fallback & direct BSH matching on server

This commit is contained in:
2026-06-12 12:09:31 +02:00
parent 4f519e34b4
commit 0e0f045e84
5 changed files with 162 additions and 41 deletions
+44
View File
@@ -2,6 +2,7 @@ import {
fetchBshTidesForCoordinates,
fetchBshTidesForStation,
listNearbyBshStations,
loadBshStationIndex,
MAX_BSH_DISTANCE_KM,
type BshStationSuggestion
} from './bshTides.js'
@@ -77,9 +78,52 @@ export async function fetchTidesForStation(
}
}
function normalizeForMatching(s: string): string {
return s
.toLowerCase()
.trim()
.replace(/ae/g, 'ä')
.replace(/oe/g, 'ö')
.replace(/ue/g, 'ü')
.replace(/ss/g, 'ß');
}
export async function fetchTidesForPlace(query: string): Promise<TideProviderResult> {
const normQuery = normalizeForMatching(query)
if (normQuery) {
try {
const stations = await loadBshStationIndex()
let match = stations.find(s => normalizeForMatching(s.name) === normQuery)
if (!match) {
match = stations.find(s => normalizeForMatching(s.name).startsWith(normQuery))
}
if (match) {
console.log(`[tideProvider] Match found in BSH station index for "${query}": ${match.name} (${match.id})`)
return await fetchTidesForStation(match.id)
}
} catch (err) {
console.warn('[tideProvider] Direct BSH station lookup failed:', err)
}
}
const place = await geocodePlace(query)
if (!place) {
if (normQuery) {
try {
const stations = await loadBshStationIndex()
const match = stations.find(s =>
normalizeForMatching(s.name).includes(normQuery) ||
normQuery.includes(normalizeForMatching(s.name))
)
if (match) {
console.log(`[tideProvider] Geocoding failed. Found fallback BSH station match for "${query}": ${match.name} (${match.id})`)
return await fetchTidesForStation(match.id)
}
} catch (err) {
console.warn('[tideProvider] Fallback BSH station lookup failed:', err)
}
}
const err = new Error('place_not_found') as Error & { status?: number }
err.status = 404
throw err