stackage-server/Handler/Download.hs

50 lines
1.5 KiB
Haskell
Raw Permalink Normal View History

module Handler.Download
( getDownloadR
2015-05-01 08:39:24 +00:00
, getDownloadSnapshotsJsonR
, getDownloadLtsSnapshotsJsonR
, getGhcMajorVersionR
, getDownloadGhcLinksR
) where
import Import
import Data.GhcLinks
import Yesod.GitRepo (grContent)
2015-05-11 17:23:09 +00:00
import Stackage.Database
import qualified Data.Text as T
getDownloadR :: Handler Html
getDownloadR = redirectWith status301 InstallR
2015-05-01 08:39:24 +00:00
getDownloadSnapshotsJsonR :: Handler Value
getDownloadSnapshotsJsonR = getDownloadLtsSnapshotsJsonR
getDownloadLtsSnapshotsJsonR :: Handler Value
getDownloadLtsSnapshotsJsonR = snapshotsJSON
-- Print the ghc major version for the given snapshot.
ghcMajorVersionText :: Snapshot -> Text
ghcMajorVersionText =
getMajorVersion . snapshotGhc
where
getMajorVersion :: Text -> Text
getMajorVersion = intercalate "." . take 2 . T.splitOn "."
2015-05-11 17:23:09 +00:00
getGhcMajorVersionR :: SnapName -> Handler Text
getGhcMajorVersionR name = do
snapshot <- lookupSnapshot name >>= maybe notFound return
return $ ghcMajorVersionText $ entityVal snapshot
getDownloadGhcLinksR :: SupportedArch -> Text -> Handler TypedContent
getDownloadGhcLinksR arch fileName = do
ver <- maybe notFound return
$ stripPrefix "ghc-"
>=> stripSuffix "-links.yaml"
>=> ghcMajorVersionFromText
$ fileName
ghcLinks <- getYesod >>= fmap wcGhcLinks . liftIO . grContent . websiteContent
case lookup (arch, ver) (ghcLinksMap ghcLinks) of
Just text -> return $ TypedContent yamlMimeType $ toContent text
Nothing -> notFound
where
yamlMimeType = "text/yaml"