Skip to content
4 changes: 2 additions & 2 deletions app/Controllers/Graph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/Controllers/Timetable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions app/Export/GetImages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ module Export.GetImages

import Config (runDb)
import Data.Aeson (decode)
import Data.ByteString.Char8 as BC (pack)
import Data.ByteString.Lazy (fromStrict)
import Data.Char (isAlphaNum)
import Data.Fixed (mod')
import qualified Data.Map as M
import Data.Maybe (fromMaybe)
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import Database.Tables as Tables
import Export.ImageConversion (createImageFile)
import Export.TimetableImageCreator (renderTableHelper, times)
Expand All @@ -28,9 +28,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 $ decode $ fromStrict $ TE.encodeUtf8 graphInfo :: M.Map T.Text T.Text
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now we're using the Aeson decode function, but you should be able to instead use decodeStrictText to simplify the conversions here.

I don't think the encodeUtf8 call is necessary, as the Happstack docs say that the lookText function assumed the data is UTF-8 encoded already.

graphName = fromMaybe "Computer-Science" $ M.lookup "active-graph" graphInfoMap
getGraphImage graphName graphInfoMap svgHandle

Expand Down