Start working on multiple data backends
This commit is contained in:
parent
8733c4d1d1
commit
6cabe97b30
@ -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
|
||||
|
@ -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 }
|
||||
|
Loading…
Reference in New Issue
Block a user