Add PDF.js

This commit is contained in:
Paul Brinkmeier
2026-05-17 20:09:05 +02:00
parent 5ee534c42c
commit 7ee3b26b7a
409 changed files with 179189 additions and 3 deletions
+8 -3
View File
@@ -26,12 +26,14 @@ import Servant
, Get
, Handler
, MimeRender (..)
, Raw
, ServerError (..)
, ServerT
, err404
, err500
, hoistServer
, serve
, serveDirectoryWebApp
, (:<|>) (..)
, (:>)
, pattern MkHandler
@@ -63,9 +65,9 @@ import Yore.Time (addYears, getCurrentDay, getSecondsUntilMidnight)
import Data.Fixed (Pico)
import Data.Time.Clock.POSIX (getPOSIXTime)
import qualified Envy
import System.IO (BufferMode (..), hSetBuffering, stdout)
import qualified Yore.DB as DB
import qualified Yore.Log as Log
import System.IO (hSetBuffering, BufferMode (..), stdout)
data ConfigT f = Config
{ yorePort :: f =@@ Int ? 3000
@@ -190,10 +192,11 @@ encodeUtf8LBS = LBS.fromStrict . Encoding.encodeUtf8 . Text.pack
type API =
Get '[HTML] RootModel
:<|> "today" :> "issue" :> Capture "issue" Int :> Get '[HTML] RootModel
:<|> "static" :> Raw
:<|> "api" :> "today" :> "issue" :> Capture "issue" Int :> "fz.pdf" :> GetSendfile
server :: Config -> DB -> ServerT API (ExceptT Error IO)
server cfg db = rootR :<|> todayR :<|> apiTodayR
server cfg db = rootR :<|> todayR :<|> staticR :<|> apiTodayR
where
rootR = todayR 0
@@ -203,6 +206,8 @@ server cfg db = rootR :<|> todayR :<|> apiTodayR
dayFile <- DB.withConn db $ DB.getDayFileByIssue dateThen issue
pure $ RootModel dateThen dayFile issue count
staticR = serveDirectoryWebApp "static"
apiTodayR issue = do
dateThen <- getTodayWithOffset (-100) 0
dayFile <- DB.withConn db $ DB.getDayFileByIssue dateThen issue
@@ -238,7 +243,7 @@ instance MimeRender HTML RootModel where
H.iframe ! A.src (H.toValue url) ! A.class_ "content" $ mempty
where
url :: String
url = printf "/api/today/issue/%d/fz.pdf" issue
url = printf "/static/pdfjs-5.7.284-dist/web/viewer.html?file=/api/today/issue/%d/fz.pdf" issue
(y, m, d) = toGregorian dateThen