From c6af3665e0f2768c02208ace2190bbbc3cca0e64 Mon Sep 17 00:00:00 2001
From: polsevev <rolf.martin@glomsrud.no>
Date: Fri, 5 May 2023 16:09:12 +0200
Subject: [PATCH] Broken reading of config file. Need to create som sort of
 singleton at start of app so we don't need to read the config file multiple
 times

---
 Config/config.json         |  2 +-
 mtgsearch.cabal            |  3 +++
 package.yaml               |  1 +
 src/Algorithm/Search.hs    |  6 +-----
 src/Config.hs              | 17 +++++++++--------
 src/Site/Static/index.html |  2 +-
 6 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/Config/config.json b/Config/config.json
index a041ee1..7a2218a 100644
--- a/Config/config.json
+++ b/Config/config.json
@@ -1,5 +1,5 @@
 {
-    "dataseedpath" : "./data/small.json",
+    "dataseedpath" : "data/small.json",
     "dbPath" : "data/db.db",
     "bulkDataLink" : "https://data.scryfall.io/default-cards/default-cards-20230430090702.json"
 }
diff --git a/mtgsearch.cabal b/mtgsearch.cabal
index 4f02975..7b7ea58 100644
--- a/mtgsearch.cabal
+++ b/mtgsearch.cabal
@@ -48,6 +48,7 @@ library
     , http-client-tls
     , scotty
     , sqlite-simple
+    , strict
     , text
   default-language: Haskell2010
 
@@ -68,6 +69,7 @@ executable mtgsearch-exe
     , mtgsearch
     , scotty
     , sqlite-simple
+    , strict
     , text
   default-language: Haskell2010
 
@@ -89,5 +91,6 @@ test-suite mtgsearch-test
     , mtgsearch
     , scotty
     , sqlite-simple
+    , strict
     , text
   default-language: Haskell2010
diff --git a/package.yaml b/package.yaml
index 9dff094..d4e0773 100644
--- a/package.yaml
+++ b/package.yaml
@@ -29,6 +29,7 @@ dependencies:
 - directory
 - http-client
 - http-client-tls
+- strict
 ghc-options:
 - -Wall
 - -Wcompat
diff --git a/src/Algorithm/Search.hs b/src/Algorithm/Search.hs
index c244627..386b4e6 100644
--- a/src/Algorithm/Search.hs
+++ b/src/Algorithm/Search.hs
@@ -67,7 +67,7 @@ cardToHtml (Card _ _ _ _ _ _ _ _ [cardFace]) = singleCardFaceHTML cardFace
 cardToHtml (Card _ _ _ _ _ _ _ _ cardFaces) = "<div style=\"text-align:center;\"><div style=\"display: inline-flex\">" ++ concatMap singleCardFaceHTML cardFaces ++"</div></div>"
 
 singleCardFaceHTML :: CardFace -> String
-singleCardFaceHTML (CardFace _ _ name cmc oracle_text type_line mana_cost (ImageUris _ _ _ image _ _ _ _)) =
+singleCardFaceHTML (CardFace _ _ name _ oracle_text type_line mana_cost (ImageUris _ _ _ image _ _ _ _)) =
   "<div style=\"text-align:center;\">" ++
     "<h2>" ++ unpack name ++ "</h2>" ++
     "<img src=" ++ unpack image ++ " width=\"200px\"/>"++
@@ -76,7 +76,3 @@ singleCardFaceHTML (CardFace _ _ name cmc oracle_text type_line mana_cost (Image
     "<p style=\"width:205px;margin: 5 auto;font-size:16;\">Mana cost: " ++  filter (`notElem` ['{','}']) (unpack (Data.Maybe.fromMaybe "" mana_cost)) ++ "</p>"++
   " </div>"
 
-
-parseCMC :: Maybe Int -> String
-parseCMC (Just a) = show a
-parseCMC Nothing = ""
\ No newline at end of file
diff --git a/src/Config.hs b/src/Config.hs
index ee811dc..3875bd1 100644
--- a/src/Config.hs
+++ b/src/Config.hs
@@ -6,13 +6,14 @@ import Data.Aeson
 import Data.Text
 
 import qualified Data.ByteString.Lazy as B
+import qualified Data.ByteString.Lazy.Char8 as C8 (pack)
 import GHC.Generics
 import Control.Exception (try)
-import Data.ByteString.Builder (lazyByteString)
-import qualified Data.Aeson.Key as B
-import qualified Data.Data as B
+
 import GHC.IO.Exception
 
+import System.IO.Strict as L
+import Data.ByteString.Builder (lazyByteString)
 
 
 data Config = Config{
@@ -31,10 +32,10 @@ configFile = "./Config/config.json"
 
 getJSON :: IO B.ByteString
 getJSON = do
-    a <- try $ B.readFile configFile :: IO (Either IOException B.ByteString )
+    a <- try $ L.readFile configFile :: IO (Either IOException String)
     case a of
-        Right a -> return a
-        Left b -> error $ "Could not load configuration file"
+        Right a2 -> return $ C8.pack a2
+        Left b -> error $ "Could not load configuration file " ++ (show b)
 
 
 
@@ -51,11 +52,11 @@ readConfig = do
 getConfig :: IO Config
 getConfig = extract readConfig
 
-getDataSeedPath ::IO (String)
+getDataSeedPath ::IO String
 getDataSeedPath = do
     dataseedpath <$> getConfig
 
-getDbPath ::IO (String)
+getDbPath ::IO String
 getDbPath = do
     dbPath <$> getConfig
 
diff --git a/src/Site/Static/index.html b/src/Site/Static/index.html
index 48eaa6a..5f66075 100644
--- a/src/Site/Static/index.html
+++ b/src/Site/Static/index.html
@@ -5,7 +5,7 @@
     <div style="text-align: center;">
         <h1>TMagic the gathering search engine!</h1>
 
-        <p>This site will be to search for magic the gathering cards using a custom sort of DSL!</p>
+        <p>In order to use this site</p>
     
     
         <form style="text-align: center;" method="POST" action="/api/req">