mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 18:21:52 +00:00
31 lines
935 B
Haskell
31 lines
935 B
Haskell
{-# LANGUAGE DataKinds #-}
|
|
{-# LANGUAGE TypeApplications #-}
|
|
{-# LANGUAGE RecordWildCards #-}
|
|
|
|
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
|
|
import Settings
|
|
import System.FilePath ((</>))
|
|
|
|
getIconsR :: Extension "png" -> Handler TypedContent
|
|
getIconsR ext = do
|
|
AppSettings{..} <- appSettings <$> getYesod
|
|
mPng <- liftIO $ getUnversionedFileFromDir (resourcesDir </> "icons") 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
|