diff --git a/CHANGELOG.md b/CHANGELOG.md index daa2af344..91bd9edda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Remove unused `getTimetableImage` function in `Export/GetImages.hs` - Refactored various backend text functions and tests to avoid `String` data in favour of `Text` when feasible - Removed unused files +- Refactored controllers to retrieve graph info data using `lookText'` instead of `look` ## [0.7.2] - 2025-12-10 diff --git a/app/Controllers/Graph.hs b/app/Controllers/Graph.hs index cc2c34171..cf241b0e0 100644 --- a/app/Controllers/Graph.hs +++ b/app/Controllers/Graph.hs @@ -4,7 +4,7 @@ import Control.Monad.IO.Class (liftIO) import Data.Aeson (decode, object, (.=)) import Data.Maybe (fromMaybe) import Export.ImageConversion (createImageFile) -import Happstack.Server (Response, ServerPart, look, lookBS, lookText', ok, toResponse) +import Happstack.Server (Response, ServerPart, lookBS, lookText', ok, toResponse) import MasterTemplate (masterTemplate) import Scripts (graphScripts) import System.IO (hClose) @@ -53,7 +53,7 @@ getGraphJSON = do -- | Returns an image of the graph requested by the user, given graphInfo stored in local storage. graphImageResponse :: ServerPart Response graphImageResponse = do - graphInfo <- look "JsonLocalStorageObj" + graphInfo <- lookText' "JsonLocalStorageObj" liftIO $ withSystemTempFile "graph.svg" $ \svgPath svgHandle -> do withSystemTempFile "graph.png" $ \pngPath pngHandle -> do hClose pngHandle diff --git a/app/Controllers/Timetable.hs b/app/Controllers/Timetable.hs index 22b99efb9..7c56fec49 100644 --- a/app/Controllers/Timetable.hs +++ b/app/Controllers/Timetable.hs @@ -57,7 +57,7 @@ exportTimetableImageResponse = do exportTimetablePDFResponse :: ServerPart Response exportTimetablePDFResponse = do selectedCourses <- lookText' "courses" - graphInfo <- look "JsonLocalStorageObj" + graphInfo <- lookText' "JsonLocalStorageObj" liftIO $ withSystemTempDirectory "timetable-pdf" $ \tempDir -> do let graphSvgPath = tempDir "graph.svg" diff --git a/app/Export/GetImages.hs b/app/Export/GetImages.hs index 93ef4ff1f..197c131f8 100644 --- a/app/Export/GetImages.hs +++ b/app/Export/GetImages.hs @@ -10,9 +10,7 @@ module Export.GetImages (getActiveTimetable, writeActiveGraphImage) where import Config (runDb) -import Data.Aeson (decode) -import Data.ByteString.Char8 as BC (pack) -import Data.ByteString.Lazy (fromStrict) +import Data.Aeson (decodeStrictText) import Data.Char (isAlphaNum) import Data.Fixed (mod') import qualified Data.Map as M @@ -28,9 +26,9 @@ import System.IO (Handle) -- | If there is an active graph available, an image of the active graph is written, -- otherwise the Computer Science graph is written as a default. -writeActiveGraphImage :: String -> Handle -> IO () +writeActiveGraphImage :: T.Text -> Handle -> IO () writeActiveGraphImage graphInfo svgHandle = do - let graphInfoMap = fromMaybe M.empty $ decode $ fromStrict $ BC.pack graphInfo :: M.Map T.Text T.Text + let graphInfoMap = fromMaybe M.empty $ decodeStrictText graphInfo :: M.Map T.Text T.Text graphName = fromMaybe "Computer-Science" $ M.lookup "active-graph" graphInfoMap getGraphImage graphName graphInfoMap svgHandle