summaryrefslogtreecommitdiff
path: root/app/Main.hs
diff options
context:
space:
mode:
authorstuebinm2025-08-27 00:29:17 +0200
committerstuebinm2026-01-01 19:58:42 +0100
commitf4794955c23d337ca25f44b771d574cc0ce970be (patch)
tree8e11c0e2cae5dc9b7329d24c3b81919422db7c83 /app/Main.hs
parentdabe335b06145f39ea36f4841459cbf5c213be14 (diff)
rnv.bahnhof.name: draft
Diffstat (limited to 'app/Main.hs')
-rw-r--r--app/Main.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 34442de..b03cdd1 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -73,6 +73,8 @@ data AppData = AppData
, leitpunktMap :: DoubleMap Ril100 Text
, ril100set :: FuzzySet
, ril100BaseUrl :: Text
+ , rnvBaseUrl :: Text
+ , rnvMap :: DoubleMap RnvId Text
, leitpunktBaseUrl :: Text
, clientManager :: Client.Manager
, platformCache :: TVar (Map Ril100 (UTCTime, Answer))
@@ -98,6 +100,9 @@ app AppData{..} request respond = mkAnswer >>= (respond . toResponse)
-> 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
@@ -108,6 +113,9 @@ app AppData{..} request respond = mkAnswer >>= (respond . toResponse)
>>= (`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
@@ -252,11 +260,12 @@ main :: IO ()
main = do
StaticAppData {..} <- readData
- putStrLn "Building index…"
- putStrLn (seq ril100set "Index generated.")
+ putStrLn "building Index ..."
+ putStrLn (seq ril100set "done")
let ril100BaseUrl = "https://ril100.bahnhof.name"
let leitpunktBaseUrl = "https://leitpunkt.bahnhof.name"
+ let rnvBaseUrl = "https://rnv.bahnhof.name"
let cacheTime = 3600 * 24 * 7 -- one week
platformCache <- newTVarIO mempty