2015-04-15 23:35:19 +00:00
|
|
|
module Handler.Download
|
|
|
|
( getDownloadR
|
2015-05-01 08:39:24 +00:00
|
|
|
, getDownloadSnapshotsJsonR
|
2015-04-16 01:26:26 +00:00
|
|
|
, getDownloadLtsSnapshotsJsonR
|
2015-04-21 23:29:58 +00:00
|
|
|
, getGhcMajorVersionR
|
2015-04-24 20:43:52 +00:00
|
|
|
, getDownloadGhcLinksR
|
2015-04-15 23:35:19 +00:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Import
|
2015-04-24 20:43:52 +00:00
|
|
|
import Data.GhcLinks
|
|
|
|
import Yesod.GitRepo (grContent)
|
2015-05-11 17:23:09 +00:00
|
|
|
import Stackage.Database
|
2015-05-20 09:13:17 +00:00
|
|
|
import qualified Data.Text as T
|
2015-04-15 23:35:19 +00:00
|
|
|
|
|
|
|
getDownloadR :: Handler Html
|
2015-08-13 08:34:05 +00:00
|
|
|
getDownloadR = redirectWith status301 InstallR
|
2015-04-15 23:35:19 +00:00
|
|
|
|
2015-05-01 08:39:24 +00:00
|
|
|
getDownloadSnapshotsJsonR :: Handler Value
|
|
|
|
getDownloadSnapshotsJsonR = getDownloadLtsSnapshotsJsonR
|
|
|
|
|
2015-04-16 01:26:26 +00:00
|
|
|
getDownloadLtsSnapshotsJsonR :: Handler Value
|
2015-06-23 08:01:28 +00:00
|
|
|
getDownloadLtsSnapshotsJsonR = snapshotsJSON
|
2015-05-01 07:15:43 +00:00
|
|
|
|
2015-05-02 04:28:37 +00:00
|
|
|
-- Print the ghc major version for the given snapshot.
|
2015-05-20 09:13:17 +00:00
|
|
|
ghcMajorVersionText :: Snapshot -> Text
|
|
|
|
ghcMajorVersionText =
|
|
|
|
getMajorVersion . snapshotGhc
|
|
|
|
where
|
|
|
|
getMajorVersion :: Text -> Text
|
|
|
|
getMajorVersion = intercalate "." . take 2 . T.splitOn "."
|
2015-04-21 23:29:58 +00:00
|
|
|
|
2015-05-11 17:23:09 +00:00
|
|
|
getGhcMajorVersionR :: SnapName -> Handler Text
|
2015-05-20 09:13:17 +00:00
|
|
|
getGhcMajorVersionR name = do
|
|
|
|
snapshot <- lookupSnapshot name >>= maybe notFound return
|
|
|
|
return $ ghcMajorVersionText $ entityVal snapshot
|
2015-04-24 20:43:52 +00:00
|
|
|
|
|
|
|
getDownloadGhcLinksR :: SupportedArch -> Text -> Handler TypedContent
|
|
|
|
getDownloadGhcLinksR arch fileName = do
|
|
|
|
ver <- maybe notFound return
|
2015-05-02 04:28:37 +00:00
|
|
|
$ stripPrefix "ghc-"
|
|
|
|
>=> stripSuffix "-links.yaml"
|
|
|
|
>=> ghcMajorVersionFromText
|
2015-04-24 20:43:52 +00:00
|
|
|
$ 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"
|