Commit fbd6f30d authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge branch 'dev' into dev-ngrams-groups

parents 78b44dcf 0832de16
...@@ -17,26 +17,31 @@ import Prelude (read) ...@@ -17,26 +17,31 @@ import Prelude (read)
import System.IO (FilePath) import System.IO (FilePath)
import Data.Ini (readIniFile, lookupValue) import Data.Ini (readIniFile, lookupValue)
import Data.Either.Extra (Either(Left, Right)) import Data.Either.Extra (Either(Left, Right))
import Gargantext.Prelude import Data.Text as T
import Data.Text (Text, pack)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Control.Lens (makeLenses) import Control.Lens (makeLenses)
import Gargantext.Prelude
data GargConfig = GargConfig { _gc_url :: !Text -- | strip a given character from end of string
, _gc_url_backend_api :: !Text stripRight :: Char -> T.Text -> T.Text
stripRight c s = if T.last s == c then stripRight c (T.take (T.length s - 1) s) else s
, _gc_masteruser :: !Text data GargConfig = GargConfig { _gc_url :: !T.Text
, _gc_secretkey :: !Text , _gc_url_backend_api :: !T.Text
, _gc_masteruser :: !T.Text
, _gc_secretkey :: !T.Text
, _gc_datafilepath :: !FilePath , _gc_datafilepath :: !FilePath
, _gc_repofilepath :: !FilePath , _gc_repofilepath :: !FilePath
, _gc_frame_write_url :: !Text , _gc_frame_write_url :: !T.Text
, _gc_frame_calc_url :: !Text , _gc_frame_calc_url :: !T.Text
, _gc_frame_searx_url :: !Text , _gc_frame_searx_url :: !T.Text
, _gc_frame_istex_url :: !Text , _gc_frame_istex_url :: !T.Text
, _gc_max_docs_scrapers :: !Integer , _gc_max_docs_scrapers :: !Integer
} }
...@@ -48,23 +53,23 @@ readConfig :: FilePath -> IO GargConfig ...@@ -48,23 +53,23 @@ readConfig :: FilePath -> IO GargConfig
readConfig fp = do readConfig fp = do
ini <- readIniFile fp ini <- readIniFile fp
let ini'' = case ini of let ini'' = case ini of
Left e -> panic (pack $ "gargantext.ini not found" <> show e) Left e -> panic (T.pack $ "gargantext.ini not found" <> show e)
Right ini' -> ini' Right ini' -> ini'
let val x = case (lookupValue (pack "gargantext") (pack x) ini'') of let val x = case (lookupValue (T.pack "gargantext") (T.pack x) ini'') of
Left _ -> panic (pack $ "ERROR: add " <> x <> " to your gargantext.ini") Left _ -> panic (T.pack $ "ERROR: add " <> x <> " to your gargantext.ini")
Right p' -> p' Right p' -> p'
pure $ GargConfig (val "URL") pure $ GargConfig (stripRight '/' $ val "URL")
(val "URL_BACKEND_API") (stripRight '/' $ val "URL_BACKEND_API")
(val "MASTER_USER") (val "MASTER_USER")
(val "SECRET_KEY") (val "SECRET_KEY")
(cs $ val "DATA_FILEPATH") (cs $ val "DATA_FILEPATH")
(cs $ val "REPO_FILEPATH") (cs $ val "REPO_FILEPATH")
(val "FRAME_WRITE_URL") (stripRight '/' $ val "FRAME_WRITE_URL")
(val "FRAME_CALC_URL") (stripRight '/' $ val "FRAME_CALC_URL")
(val "FRAME_SEARX_URL") (stripRight '/' $ val "FRAME_SEARX_URL")
(val "FRAME_ISTEX_URL") (stripRight '/' $ val "FRAME_ISTEX_URL")
(read $ cs $ val "MAX_DOCS_SCRAPERS") (read $ cs $ val "MAX_DOCS_SCRAPERS")
{- UNUSED {- UNUSED
...@@ -80,4 +85,4 @@ defaultConfig = GargConfig "https://localhost" ...@@ -80,4 +85,4 @@ defaultConfig = GargConfig "https://localhost"
"https://frame_searx.url" "https://frame_searx.url"
"https://frame_istex.url" "https://frame_istex.url"
1000 1000
-} -}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment