diff options
| author | stuebinm | 2026-06-14 15:58:44 +0200 |
|---|---|---|
| committer | stuebinm | 2026-06-14 15:58:44 +0200 |
| commit | d37a8c5f1b6dd88c1ebe5310161c16a0c463defb (patch) | |
| tree | 9a4e2dc21fd095a734cfabe89b5c5822165bf176 | |
| parent | 7f690b4f530c368ec0074bb6fc4b1c35155a7615 (diff) | |
bahnhof-name: fix handling of / in request pathrnv
before, slashes in station names could not be handled, as they are split
during parsing of the incoming request to see if the last (really the
second) part was /gleis or /tracks.
Now, instead the list is un-snoc'd, and then if the last part is not one
that requires special handling, we fall through to treating it as a
station name.
| -rw-r--r-- | app/Main.hs | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/app/Main.hs b/app/Main.hs index 0c004d5..132e132 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -86,45 +86,18 @@ app :: AppData -> Application app AppData{..} request respond = mkAnswer >>= (respond . toResponse) where mkAnswer :: IO Answer - mkAnswer = case filter (/= mempty) (pathInfo request) of - [] -> pure helptext - ["favicon.ico"] -> pure Notfound - ["cache"] -> do + mkAnswer = case unsnoc (filter (/= mempty) (pathInfo request)) of + Nothing -> pure helptext + Just ([], "favicon.ico") -> pure Notfound + Just ([], "cache") -> do cache <- readTVarIO platformCache now <- getCurrentTime M.toList cache & fmap (\(ril100, (age, _)) -> (T.pack . show) (unRil100 ril100, now `diffUTCTime` age)) & T.unlines & (pure . Plaintext) - [query] - | not (T.any isLower query) && host `elem` ["leitpunkt"] - -> lookupName query leitpunktMap - >>= (`lookupCode` ril100map) - & maybeAnswer Plaintext & pure - | not (T.any isLower query) && host `elem` ["rnv"] - -> lookupCode (RnvId query) rnvMap - & maybeAnswer Plaintext & pure - | not (T.any isLower query) - -> lookupCode (Ril100 query) ril100map - & maybeAnswer Plaintext & pure - | host `elem` ["leitpunkt"] - -> pure $ case findStationName query ril100set of - None -> Notfound - Exact (_,match) -> lookupName match ril100map - >>= (`lookupCode` leitpunktMap) - & maybeAnswer Plaintext - Fuzzy (_,match) -> Redirect (leitpunktBaseUrl <> "/" <> match) - | host `elem` ["rnv"] - -> lookupName query rnvMap - & maybeAnswer (Plaintext . unRnv) & pure - | otherwise - -> pure $ case findStationName query ril100set of - None -> Notfound - Exact (_,match) -> lookupName match ril100map - & maybeAnswer (Plaintext . unRil100) - Fuzzy (_,match) -> Redirect (ril100BaseUrl <> "/" <> match) - [query, segment] | segment `elem` ["gleis", "track", "tracks", "gleise", "platform", "platforms", "fetch"] - -> case queriedRil100 query of + Just (query, segment) | segment `elem` ["gleis", "track", "tracks", "gleise", "platform", "platforms", "fetch"] + -> case queriedRil100 (T.intercalate "/" query) of None -> pure Notfound Fuzzy url -> pure (Redirect (T.intercalate "/" [url, segment])) Exact ril100 -> do @@ -209,6 +182,34 @@ app AppData{..} request respond = mkAnswer >>= (respond . toResponse) & T.intercalate " " mkAnchor p inner = "<a href=\"https://osm.org/"<>osmType p<>"/"<>osmId p<>"\">"<>inner<>"</a>" + Just _ + | not (T.any isLower query) && host `elem` ["leitpunkt"] + -> lookupName query leitpunktMap + >>= (`lookupCode` ril100map) + & maybeAnswer Plaintext & pure + | not (T.any isLower query) && host `elem` ["rnv"] + -> lookupCode (RnvId query) rnvMap + & maybeAnswer Plaintext & pure + | not (T.any isLower query) + -> lookupCode (Ril100 query) ril100map + & maybeAnswer Plaintext & pure + | host `elem` ["leitpunkt"] + -> pure $ case findStationName query ril100set of + None -> Notfound + Exact (_,match) -> lookupName match ril100map + >>= (`lookupCode` leitpunktMap) + & maybeAnswer Plaintext + Fuzzy (_,match) -> Redirect (leitpunktBaseUrl <> "/" <> match) + | host `elem` ["rnv"] + -> lookupName query rnvMap + & maybeAnswer (Plaintext . unRnv) & pure + | otherwise + -> pure $ case findStationName query ril100set of + None -> Notfound + Exact (_,match) -> lookupName match ril100map + & maybeAnswer (Plaintext . unRil100) + Fuzzy (_,match) -> Redirect (ril100BaseUrl <> "/" <> match) + where query = T.intercalate "/" (pathInfo request) _ -> pure Notfound queriedRil100 :: Text -> MatchResult Ril100 Text queriedRil100 query = if |
