adds icons endpoint

This commit is contained in:
Aaron Greenspan
2020-01-02 14:42:59 -07:00
parent 87bb534ebf
commit d8b5d3e193
11 changed files with 105 additions and 76 deletions

26
src/Handler/Icons.hs Normal file
View File

@@ -0,0 +1,26 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}
module Handler.Icons where
import Startlude
import Data.Conduit
import qualified Data.Conduit.Binary as CB
import System.Directory
import Yesod.Core
import Foundation
import Lib.Registry
getIconsR :: Extension "png" -> Handler TypedContent
getIconsR ext = do
mPng <- liftIO $ getUnversionedFileFromDir iconsResourceDir ext
case mPng of
Nothing -> notFound
Just pngPath -> do
putStrLn @Text $ show pngPath
exists <- liftIO $ doesFileExist pngPath
if exists
then respondSource typePlain $ CB.sourceFile pngPath .| awaitForever sendChunkBS
else notFound