Start working on multiple data backends

This commit is contained in:
Mats Rauhala 2018-10-18 00:12:30 +03:00
parent 8733c4d1d1
commit 6cabe97b30
2 changed files with 7 additions and 5 deletions

View File

@ -31,11 +31,11 @@ instance MonadDS AppM where
putLocal :: ( MonadIO m
, HasField "config" r r config config
, HasField "store" config config store store
, HasField "path" store store Text Text
, HasType Text store
, MonadReader r m)
=> ByteString -> m (Digest SHA256)
putLocal bs = do
store :: FilePath <- unpack <$> view (field @"config" . field @"store" . field @"path")
store :: FilePath <- unpack <$> view (field @"config" . field @"store" . typed @Text)
liftIO $ createDirectoryIfMissing True store
let key = hashWith SHA256 bs
writeFile (store </> show key) bs
@ -44,11 +44,11 @@ putLocal bs = do
getLocal :: ( MonadIO m
, HasField "config" r r config config
, HasField "store" config config store store
, HasField "path" store store Text Text
, HasType Text store
, MonadReader r m)
=> Digest SHA256 -> m (Maybe ByteString)
getLocal key = do
store <- unpack <$> view (field @"config" . field @"store" . field @"path")
store <- unpack <$> view (field @"config" . field @"store" . typed @Text)
liftIO $ createDirectoryIfMissing True store
let file = store </> show key
exists <- liftIO $ doesFileExist file

View File

@ -12,7 +12,9 @@ data Pg = Pg { username :: Text
, database :: Text }
deriving (Show, Generic)
newtype Store = Store { path :: Text } deriving (Show, Generic)
data Store = Filestore { path :: Text }
| IPFS { common :: Text }
deriving (Show, Generic)
data Config = Config { database :: Pg
, store :: Store }