From 88d9708a9f8717d31aa89d7afef6a3a322b913ef Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Sun, 31 Mar 2024 21:38:56 -0400 Subject: [PATCH] Build another binary, parse settings --- backfill_settings.json | 2 +- chan-delorean.cabal | 53 ++++++++++++++++++++++++++++++++++++++++++ consumer_settings.json | 9 +++++++ src/Common | 2 +- src/Main.hs | 38 ++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 consumer_settings.json create mode 100644 src/Main.hs diff --git a/backfill_settings.json b/backfill_settings.json index cfe5fc2..b38a623 100644 --- a/backfill_settings.json +++ b/backfill_settings.json @@ -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" } diff --git a/chan-delorean.cabal b/chan-delorean.cabal index 655dbf7..9f65b09 100644 --- a/chan-delorean.cabal +++ b/chan-delorean.cabal @@ -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 diff --git a/consumer_settings.json b/consumer_settings.json new file mode 100644 index 0000000..73bdbbe --- /dev/null +++ b/consumer_settings.json @@ -0,0 +1,9 @@ +{ + "websites": { + "name": "leftychan", + "root_url": "https://leftychan.net" + }, + "postgrest_url": "http://localhost:3000", + "jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiY2hhbl9hcmNoaXZlciJ9.rGIKZokTDKTuQLIv8138bUby5PELfDipYYIDpJzH02c", + "media_root_path": "/home/phil/linixy/tmp/chan_archive_media2/archive" +} diff --git a/src/Common b/src/Common index 62a2358..d47fbe7 160000 --- a/src/Common +++ b/src/Common @@ -1 +1 @@ -Subproject commit 62a23581e786f8564653406845c4b2a07d73deb6 +Subproject commit d47fbe70c6c40ad6963411d6ffbbadc1839b5b7c diff --git a/src/Main.hs b/src/Main.hs new file mode 100644 index 0000000..540f4ff --- /dev/null +++ b/src/Main.hs @@ -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