Apply max-age header to bust PDF cache at midnight
Also update stylish-haskell config
This commit is contained in:
+13
-5
@@ -1,6 +1,6 @@
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE OverloadedRecordDot #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Main (main) where
|
||||
|
||||
@@ -29,6 +29,7 @@ import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
|
||||
import Text.Blaze.Html5 ((!))
|
||||
import Text.Printf (printf)
|
||||
|
||||
import qualified Data.ByteString.Char8 as BS8
|
||||
import qualified Data.Text as Text
|
||||
import qualified Database.PostgreSQL.Opium as Opium
|
||||
import Network.Wai (responseFile)
|
||||
@@ -37,7 +38,7 @@ import qualified Text.Blaze.Html5 as H
|
||||
import qualified Text.Blaze.Html5.Attributes as A
|
||||
|
||||
import Yore.DB (DayFile (..))
|
||||
import Yore.Time (addYears, getCurrentDay)
|
||||
import Yore.Time (addYears, getCurrentDay, getSecondsUntilMidnight)
|
||||
|
||||
import qualified Yore.DB as DB
|
||||
|
||||
@@ -68,7 +69,7 @@ server connPool = rootR :<|> todayR :<|> apiTodayR
|
||||
rootR = todayR 0
|
||||
|
||||
todayR issue = do
|
||||
dateThen <- liftIO $ get100YearsAgo
|
||||
dateThen <- liftIO get100YearsAgo
|
||||
Right count <- liftIO $ withResource connPool $ DB.getNumberOfIssues dateThen
|
||||
Right dayFile <- liftIO $ withResource connPool $ DB.getDayFileByIssue dateThen issue
|
||||
pure $ RootModel dateThen dayFile issue count
|
||||
@@ -79,8 +80,15 @@ server connPool = rootR :<|> todayR :<|> apiTodayR
|
||||
res <- withResource connPool $ DB.getDayFileByIssue dateThen issue
|
||||
dayFile <- either throwIO pure res
|
||||
let fullPath = "download" </> dayFile.relative_path
|
||||
secondsUntilMidnight <- getSecondsUntilMidnight
|
||||
|
||||
respond $ responseFile status200 [("content-type", "application/pdf")] fullPath Nothing
|
||||
respond $ responseFile
|
||||
status200
|
||||
[ ("content-type", "application/pdf")
|
||||
, ("cache-control", BS8.pack $ printf "public, max-age=%d" secondsUntilMidnight)
|
||||
]
|
||||
fullPath
|
||||
Nothing
|
||||
|
||||
data RootModel = RootModel Day DB.DayFile Int Int
|
||||
|
||||
|
||||
Reference in New Issue
Block a user