module Network.Syncthing.Types.DirTree
( DirTree(..)
) where
import Control.Applicative ((<$>))
import Control.Monad (MonadPlus (mzero))
import Data.Aeson (FromJSON, Value (..), parseJSON)
import qualified Data.Map as M
import Data.Text (Text)
data DirTree
= Dir {
getDirContents :: M.Map Text DirTree
}
| File {
getModTime :: Integer
, getFileSize :: Integer
}
deriving (Eq, Show)
instance FromJSON DirTree where
parseJSON obj@(Object _) = Dir <$> parseJSON obj
parseJSON arr@(Array _) = decodeFile <$> parseJSON arr
parseJSON _ = mzero
decodeFile :: [Integer] -> DirTree
decodeFile [modTime, fileSize] = File modTime fileSize
decodeFile _ = File 0 0