From 63b06627f200f155f66ecdb6c5f41ab44808dd6b Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 27 Dec 2019 12:38:01 +0100 Subject: compiler: add compiler config keys --- compiler/src/Config.hs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'compiler/src/Config.hs') diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index f147bdd..fe981c3 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs @@ -20,6 +20,7 @@ DuplicateRecordFields , DeriveGeneric , DeriveAnyClass + , OverloadedStrings #-} module Config @@ -29,25 +30,31 @@ module Config ) where +import Data.Text (Text) import GHC.Generics (Generic) -import Data.Aeson (ToJSON, FromJSON) +import Data.Aeson (ToJSON, FromJSON, withObject, (.:?), (.!=)) import qualified Data.Aeson as JSON import Files (FileName) import Input (decodeYamlFile) +import Processors (Resolution(..)) data CompilerConfig = CompilerConfig - { dummy :: Maybe String -- TODO - } deriving (Generic, FromJSON, Show) + { thumbnailResolution :: Resolution + , pictureMaxResolution :: Maybe Resolution + } deriving (Generic, Show) + +instance FromJSON CompilerConfig where + parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig + <$> v .:? "thumbnailResolution" .!= (Resolution 400 400) + <*> v .:? "pictureMaxResolution" + data GalleryConfig = GalleryConfig { compiler :: CompilerConfig , viewer :: JSON.Object } deriving (Generic, FromJSON, Show) --- TODO: add compiler config keys and their default values - - readConfig :: FileName -> IO GalleryConfig readConfig = decodeYamlFile -- cgit v1.2.3