diff --git a/Application.hs b/Application.hs index 78fd8e8..dd07e0e 100644 --- a/Application.hs +++ b/Application.hs @@ -74,6 +74,7 @@ import Handler.BuildVersion import Handler.PackageCounts import Handler.Sitemap import Handler.BuildPlan +import Handler.Download -- This line actually creates our YesodDispatch instance. It is the second half -- of the call to mkYesodData which occurs in Foundation.hs. Please see the diff --git a/Handler/Download.hs b/Handler/Download.hs new file mode 100644 index 0000000..323d66b --- /dev/null +++ b/Handler/Download.hs @@ -0,0 +1,28 @@ +module Handler.Download + ( getDownloadR + , getDownloadStackageExecutableR + ) where + +import Import + +executableFor :: SupportedArch -> StackageExecutable +executableFor Win32 = StackageWindowsExecutable +executableFor Win64 = StackageWindowsExecutable +executableFor _ = StackageUnixExecutable + +downloadCandidates :: [(SupportedArch, StackageExecutable)] +downloadCandidates = + map (\arch -> (arch, executableFor arch)) + [minBound .. maxBound] + +getDownloadR :: Handler Html +getDownloadR = defaultLayout $ do + $(widgetFile "download") + +getDownloadStackageExecutableR + :: SupportedArch -> StackageExecutable -> Handler Html +getDownloadStackageExecutableR arch exe = do + -- TODO: send exeutable file instead + when (executableFor arch /= exe) notFound + defaultLayout $ do + $(widgetFile "downloadExe") diff --git a/Types.hs b/Types.hs index ed79874..3e55df4 100644 --- a/Types.hs +++ b/Types.hs @@ -102,3 +102,41 @@ instance HasHackageRoot HackageRoot where data UnpackStatus = USReady | USBusy | USFailed !Text + +data StackageExecutable + = StackageWindowsExecutable + | StackageUnixExecutable + deriving (Show, Read, Eq) + +instance PathPiece StackageExecutable where + toPathPiece StackageWindowsExecutable = "stackage.exe" + toPathPiece StackageUnixExecutable = "stackage" + + fromPathPiece "stackage" = Just StackageUnixExecutable + fromPathPiece "stackage.exe" = Just StackageWindowsExecutable + fromPathPiece _ = Nothing + +data SupportedArch + = Win32 + | Win64 + | Linux32 + | Linux64 + | Mac32 + | Mac64 + deriving (Enum, Bounded, Show, Read, Eq) + +instance PathPiece SupportedArch where + toPathPiece Win32 = "win32" + toPathPiece Win64 = "win64" + toPathPiece Linux32 = "linux32" + toPathPiece Linux64 = "linux64" + toPathPiece Mac32 = "mac32" + toPathPiece Mac64 = "mac64" + + fromPathPiece "win32" = Just Win32 + fromPathPiece "win64" = Just Win64 + fromPathPiece "linux32" = Just Linux32 + fromPathPiece "linux64" = Just Linux64 + fromPathPiece "mac32" = Just Mac32 + fromPathPiece "mac64" = Just Mac64 + fromPathPiece _ = Nothing diff --git a/config/routes b/config/routes index 9fc3c7a..b851e28 100644 --- a/config/routes +++ b/config/routes @@ -57,3 +57,6 @@ /upload2 UploadV2R PUT /build-version BuildVersionR GET /package-counts PackageCountsR GET + +/download DownloadR GET +/download/#SupportedArch/#StackageExecutable DownloadStackageExecutableR GET diff --git a/stackage-server.cabal b/stackage-server.cabal index b07b75d..7bfdda2 100644 --- a/stackage-server.cabal +++ b/stackage-server.cabal @@ -54,6 +54,7 @@ library Handler.PackageCounts Handler.Sitemap Handler.BuildPlan + Handler.Download if flag(dev) || flag(library-only) cpp-options: -DDEVELOPMENT diff --git a/templates/download.hamlet b/templates/download.hamlet new file mode 100644 index 0000000..c5434de --- /dev/null +++ b/templates/download.hamlet @@ -0,0 +1,5 @@ +$forall (arch, exe) <- downloadCandidates +