{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}

-- | Common handler functions.
module BtcLsp.Yesod.Handler.Common where

import BtcLsp.Yesod.Import
import Data.FileEmbed (embedFile)

-- These handlers embed files in the executable at compile time to avoid a
-- runtime dependency, and for efficiency.

getFaviconR :: Handler TypedContent
getFaviconR :: Handler TypedContent
getFaviconR = do
  Int -> HandlerFor App ()
forall (m :: * -> *). MonadHandler m => Int -> m ()
cacheSeconds (Int -> HandlerFor App ()) -> Int -> HandlerFor App ()
forall a b. (a -> b) -> a -> b
$ Int
60 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
60 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
24 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
30 -- cache for a month
  TypedContent -> Handler TypedContent
forall (m :: * -> *) a. Monad m => a -> m a
return (TypedContent -> Handler TypedContent)
-> TypedContent -> Handler TypedContent
forall a b. (a -> b) -> a -> b
$
    ByteString -> Content -> TypedContent
TypedContent ByteString
"image/x-icon" (Content -> TypedContent) -> Content -> TypedContent
forall a b. (a -> b) -> a -> b
$
      ByteString -> Content
forall a. ToContent a => a -> Content
toContent $(embedFile "config/favicon.ico")

getRobotsR :: Handler TypedContent
getRobotsR :: Handler TypedContent
getRobotsR =
  TypedContent -> Handler TypedContent
forall (m :: * -> *) a. Monad m => a -> m a
return (TypedContent -> Handler TypedContent)
-> TypedContent -> Handler TypedContent
forall a b. (a -> b) -> a -> b
$
    ByteString -> Content -> TypedContent
TypedContent ByteString
typePlain (Content -> TypedContent) -> Content -> TypedContent
forall a b. (a -> b) -> a -> b
$
      ByteString -> Content
forall a. ToContent a => a -> Content
toContent $(embedFile "config/robots.txt")