Add PDF.js
This commit is contained in:
+8
-3
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user