Build another binary, parse settings

This commit is contained in:
towards-a-new-leftypol 2024-03-31 21:38:56 -04:00
parent 02d35a051d
commit 2588724b8c
5 changed files with 106 additions and 2 deletions

View File

@ -2,7 +2,7 @@
"postgrest_url": "http://localhost:3000",
"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiY2hhbl9hcmNoaXZlciJ9.rGIKZokTDKTuQLIv8138bUby5PELfDipYYIDpJzH02c",
"backup_read_root": "/home/phil/linixy/tmp/leftypol_back/lainchan.leftypol.org",
"media_root_path": "/home/phil/linixy/tmp/chan_archive_media",
"media_root_path": "/home/phil/linixy/tmp/chan_archive_media2/archive",
"site_name": "leftychan",
"site_url": "https://leftychan.net"
}

View File

@ -108,3 +108,56 @@ executable chan-delorean
-- Base language which the package is written in.
default-language: GHC2021
executable chan-delorean-consoomer
-- Import common warning flags.
import: warnings
-- .hs or .lhs file containing the Main module.
main-is: Main.hs
-- Modules included in this executable, other than Main.
other-modules:
JSONParsing
SitesType
BoardsType
ThreadType
JSONPost
JSONCommonTypes
Common.PostsType
Common.AttachmentType
Common.Network.HttpClient
Hash
Data.WordUtil
Network.DataClient
Network.DataClientTypes
Common.Server.ConsumerSettings
Common.Server.JSONSettings
-- LANGUAGE extensions used by modules in this package.
-- other-extensions:
-- Other library packages from which modules are imported.
build-depends: base,
aeson,
bytestring,
cmdargs,
directory,
filepath,
containers,
text,
http-client,
http-conduit,
safe-exceptions,
http-types,
time,
cryptonite,
memory,
mime-types,
perceptual-hash
-- Directories containing source files.
hs-source-dirs: src
-- Base language which the package is written in.
default-language: GHC2021

13
consumer_settings.json Normal file
View File

@ -0,0 +1,13 @@
{
"websites": {
"name": "example",
"root_url": "https://example.net",
"boards": [
"tech",
"meta"
]
},
"postgrest_url": "http://localhost:3000",
"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiY2hhbl9hcmNoaXZlciJ9.rGIKZokTDKTuQLIv8138bUby5PELfDipYYIDpJzH02c",
"media_root_path": "/home/phil/linixy/tmp/chan_archive_media2/archive"
}

@ -1 +1 @@
Subproject commit 62a23581e786f8564653406845c4b2a07d73deb6
Subproject commit d47fbe70c6c40ad6963411d6ffbbadc1839b5b7c

38
src/Main.hs Normal file
View File

@ -0,0 +1,38 @@
module Main where
import System.Exit (exitFailure)
import qualified Data.ByteString.Lazy as B
import System.Console.CmdArgs (cmdArgs, Data, Typeable)
import Data.Aeson (decode)
import Common.Server.ConsumerSettings
newtype CliArgs = CliArgs
{ settingsFile :: String
} deriving (Show, Data, Typeable)
getSettings :: IO ConsumerJSONSettings
getSettings = do
cliArgs <- cmdArgs $ CliArgs "consumer_settings.json"
let filePath = settingsFile cliArgs
if null filePath
then do
putStrLn "Error: No JSON settings file provided."
exitFailure
else do
putStrLn $ "Loading settings from: " ++ filePath
content <- B.readFile filePath
case decode content :: Maybe ConsumerJSONSettings of
Nothing -> do
putStrLn "Error: Invalid JSON format."
exitFailure
Just settings -> return settings
main :: IO ()
main = do
putStrLn "Hello World"
settings <- getSettings
print settings