Extensive commenting of functions; refactor some duplicate pattern matching logic

This commit is contained in:
2024-02-17 14:56:13 -06:00
parent 7796fcb9b4
commit 4909bb9c96
11 changed files with 105 additions and 62 deletions

View File

@@ -9,6 +9,7 @@ import Configuration.Dotenv
import System.Directory (doesFileExist)
import System.Environment (getEnv, lookupEnv)
-- Make the dotenv file configuration available if PURRNOFILE is not present
main :: IO ()
main = do
envFile <- lookupEnv "PURRNOFILE"
@@ -16,6 +17,7 @@ main = do
Nothing -> loadFile defaultConfig
_ -> putStrLn "Not using dotenv file"
-- Check if an encryption key exists on the filesystem and create one if not
keyFileInit :: IO ()
keyFileInit = do
dataPathStr <- dataPath
@@ -27,6 +29,13 @@ keyFileInit = do
B.writeFile (dataPathStr ++ "data/encryptionKey") (encode key)
putStrLn "Creating new encryption key; any pre-existing DB entries will not decrypt"
-- Read and return the encryption key on the filesystem as a ByteString
encKey :: IO B.ByteString
encKey = do
dataPathStr <- dataPath
B.readFile (dataPathStr ++ "data/encryptionKey")
-- Helper functions for getting the value of environment variables
adminEmail :: IO String
adminEmail = getEnv "ADMINEMAIL"
@@ -41,8 +50,3 @@ dbPath = "data/Purr.sqlite"
confLinkLength :: IO String
confLinkLength = getEnv "LINKLENGTH"
encKey :: IO B.ByteString
encKey = do
dataPathStr <- dataPath
B.readFile (dataPathStr ++ "data/encryptionKey")