summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2026-04-06 23:35:05 +0200
committerTom Smeding <tom@tomsmeding.com>2026-04-06 23:36:28 +0200
commit287d9e5c4fc50bcca2474b9783148181d7ede872 (patch)
tree81a80cc5f5aabb2d3cffd3874438782d32096cff /src/Main.hs
parent875da72c83b20260ac5af2bdcc8b992d657fd97e (diff)
Log watching
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/Main.hs b/src/Main.hs
index bb5bdf7..c516c5f 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -18,7 +18,7 @@ import Data.Map.Strict qualified as Map
import Data.Text (Text)
import Data.Text qualified as T
import Data.Text.Encoding qualified as TE
-import Data.Text.IO qualified as T
+import Data.Text.IO.Utf8 qualified as T
import Data.Time (Day, fromGregorianValid)
import Network.Wai
import Network.HTTP.Types
@@ -34,6 +34,7 @@ import Text.Read (readMaybe)
-- import Debug.Trace
+import AtomicPrint
import Calendar
import Config
import Index
@@ -74,7 +75,8 @@ pageLog conf pages index req alias =
case econfAlias2Chan conf Map.!? alias of
Nothing -> page404 "Channel not found"
Just chan -> do
- let npages = (indexNumEvents index chan + numPerPage - 1) `div` numPerPage
+ numEvents <- indexNumEvents index chan
+ let npages = (numEvents + numPerPage - 1) `div` numPerPage
curpage | Just (readMaybe . BS8.unpack -> Just pg) <- query "page" = min npages (max 1 pg)
| otherwise = npages
ntoleft = min 5 (curpage - 1)
@@ -85,7 +87,7 @@ pageLog conf pages index req alias =
["network" ~> chanNetwork chan
,"channel" ~> chanChannel chan
,"alias" ~> alias
- ,"totalevents" ~> renderLargeNumber (indexNumEvents index chan)
+ ,"totalevents" ~> renderLargeNumber numEvents
,"picker" ~> M.object
["prevpage" ~> if curpage > 1 then Just (curpage - 1) else Nothing
,"nextpage" ~> if curpage < npages then Just (curpage + 1) else Nothing
@@ -181,7 +183,7 @@ pageCalendar conf pages index alias =
case econfAlias2Chan conf Map.!? alias of
Nothing -> page404 "Channel not found"
Just chan -> do
- let ((startDay, endDay), counts) = indexCalendar index chan
+ ((startDay, endDay), counts) <- indexCalendar index chan
return $ sendPage200 pages "calendar" $ M.object
["network" ~> chanNetwork chan
,"channel" ~> chanChannel chan
@@ -254,7 +256,7 @@ mainServe confpath = do
settings = defaultSettings & setFork checkedFork
& setPort (confPort config)
- putStrLn $ "Listening on port " ++ show (confPort config)
+ atomicPrintS $ "Listening on port " ++ show (confPort config)
runSettings settings $ \req respond -> case pathInfo req of
[] ->
respond =<< pageIndex config pages