Start working on multiple data backends
This commit is contained in:
		@@ -31,11 +31,11 @@ instance MonadDS AppM where
 | 
				
			|||||||
putLocal :: ( MonadIO m
 | 
					putLocal :: ( MonadIO m
 | 
				
			||||||
            , HasField "config" r r config config
 | 
					            , HasField "config" r r config config
 | 
				
			||||||
            , HasField "store" config config store store
 | 
					            , HasField "store" config config store store
 | 
				
			||||||
            , HasField "path" store store Text Text
 | 
					            , HasType Text store
 | 
				
			||||||
            , MonadReader r m)
 | 
					            , MonadReader r m)
 | 
				
			||||||
            => ByteString -> m (Digest SHA256)
 | 
					            => ByteString -> m (Digest SHA256)
 | 
				
			||||||
putLocal bs = do
 | 
					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
 | 
					  liftIO $ createDirectoryIfMissing True store
 | 
				
			||||||
  let key = hashWith SHA256 bs
 | 
					  let key = hashWith SHA256 bs
 | 
				
			||||||
  writeFile (store </> show key) bs
 | 
					  writeFile (store </> show key) bs
 | 
				
			||||||
@@ -44,11 +44,11 @@ putLocal bs = do
 | 
				
			|||||||
getLocal :: ( MonadIO m
 | 
					getLocal :: ( MonadIO m
 | 
				
			||||||
            , HasField "config" r r config config
 | 
					            , HasField "config" r r config config
 | 
				
			||||||
            , HasField "store" config config store store
 | 
					            , HasField "store" config config store store
 | 
				
			||||||
            , HasField "path" store store Text Text
 | 
					            , HasType Text store
 | 
				
			||||||
            , MonadReader r m)
 | 
					            , MonadReader r m)
 | 
				
			||||||
            => Digest SHA256 -> m (Maybe ByteString)
 | 
					            => Digest SHA256 -> m (Maybe ByteString)
 | 
				
			||||||
getLocal key = do
 | 
					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
 | 
					  liftIO $ createDirectoryIfMissing True store
 | 
				
			||||||
  let file = store </> show key
 | 
					  let file = store </> show key
 | 
				
			||||||
  exists <- liftIO $ doesFileExist file
 | 
					  exists <- liftIO $ doesFileExist file
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,7 +12,9 @@ data Pg = Pg { username :: Text
 | 
				
			|||||||
             , database :: Text }
 | 
					             , database :: Text }
 | 
				
			||||||
        deriving (Show, Generic)
 | 
					        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
 | 
					data Config = Config { database :: Pg
 | 
				
			||||||
                     , store :: Store }
 | 
					                     , store :: Store }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user