mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-02-06 08:07:28 +01:00
commit
c3a59798cb
@ -1,8 +1,6 @@
|
|||||||
module Handler.Feed
|
module Handler.Feed
|
||||||
( getFeedR
|
( getFeedR
|
||||||
, getLtsFeedR
|
, getBranchFeedR
|
||||||
, getLtsMajorFeedR
|
|
||||||
, getNightlyFeedR
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Import
|
import Import
|
||||||
@ -13,21 +11,17 @@ import qualified Data.HashMap.Strict as HashMap
|
|||||||
import Text.Blaze (text)
|
import Text.Blaze (text)
|
||||||
|
|
||||||
getFeedR :: Handler TypedContent
|
getFeedR :: Handler TypedContent
|
||||||
getFeedR = mkFeed "" . snd =<< getSnapshots 20 0
|
getFeedR = getBranchFeed Nothing
|
||||||
|
|
||||||
getLtsFeedR :: Handler TypedContent
|
getBranchFeedR :: SnapshotBranch -> Handler TypedContent
|
||||||
getLtsFeedR = mkFeed "LTS" . snd =<< getLtsSnapshots 20 0
|
getBranchFeedR = getBranchFeed . Just
|
||||||
|
|
||||||
getLtsMajorFeedR :: LtsMajor -> Handler TypedContent
|
getBranchFeed :: Maybe SnapshotBranch -> Handler TypedContent
|
||||||
getLtsMajorFeedR (LtsMajor v) =
|
getBranchFeed mBranch = mkFeed mBranch =<< getSnapshots mBranch 20 0
|
||||||
mkFeed ("LTS-" <> tshow v) . snd =<< getLtsMajorSnapshots v 20 0
|
|
||||||
|
|
||||||
getNightlyFeedR :: Handler TypedContent
|
mkFeed :: Maybe SnapshotBranch -> [Entity Snapshot] -> Handler TypedContent
|
||||||
getNightlyFeedR = mkFeed "Nightly" . snd =<< getNightlySnapshots 20 0
|
|
||||||
|
|
||||||
mkFeed :: Text -> [Entity Snapshot] -> Handler TypedContent
|
|
||||||
mkFeed _ [] = notFound
|
mkFeed _ [] = notFound
|
||||||
mkFeed branch snaps = do
|
mkFeed mBranch snaps = do
|
||||||
entries <- forM snaps $ \(Entity snapid snap) -> do
|
entries <- forM snaps $ \(Entity snapid snap) -> do
|
||||||
content <- getContent snapid snap
|
content <- getContent snapid snap
|
||||||
return FeedEntry
|
return FeedEntry
|
||||||
@ -41,15 +35,20 @@ mkFeed branch snaps = do
|
|||||||
[] -> liftIO getCurrentTime
|
[] -> liftIO getCurrentTime
|
||||||
x:_ -> return $ feedEntryUpdated x
|
x:_ -> return $ feedEntryUpdated x
|
||||||
newsFeed Feed
|
newsFeed Feed
|
||||||
{ feedTitle = "Recent Stackage " <> branch <> " snapshots"
|
{ feedTitle = title
|
||||||
, feedLinkSelf = FeedR
|
, feedLinkSelf = FeedR
|
||||||
, feedLinkHome = HomeR
|
, feedLinkHome = HomeR
|
||||||
, feedAuthor = "Stackage Project"
|
, feedAuthor = "Stackage Project"
|
||||||
, feedDescription = text ("Recent Stackage " <> branch <> " snapshots")
|
, feedDescription = text title
|
||||||
, feedLanguage = "en"
|
, feedLanguage = "en"
|
||||||
, feedUpdated = updated
|
, feedUpdated = updated
|
||||||
, feedEntries = entries
|
, feedEntries = entries
|
||||||
}
|
}
|
||||||
|
where
|
||||||
|
branchTitle NightlyBranch = "Nightly"
|
||||||
|
branchTitle LtsBranch = "LTS"
|
||||||
|
branchTitle (LtsMajorBranch x) = "LTS-" <> tshow x
|
||||||
|
title = "Recent Stackage " <> maybe "" branchTitle mBranch <> " snapshots"
|
||||||
|
|
||||||
getContent :: SnapshotId -> Snapshot -> Handler Html
|
getContent :: SnapshotId -> Snapshot -> Handler Html
|
||||||
getContent sid2 snap = do
|
getContent sid2 snap = do
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
module Handler.OldLinks
|
module Handler.OldLinks
|
||||||
( getOldLtsR
|
( getOldSnapshotBranchR
|
||||||
, getOldLtsMajorR
|
|
||||||
, getOldNightlyR
|
|
||||||
, getOldSnapshotR
|
, getOldSnapshotR
|
||||||
) where
|
) where
|
||||||
|
|
||||||
@ -28,8 +26,8 @@ redirectWithQueryText url = do
|
|||||||
req <- waiRequest
|
req <- waiRequest
|
||||||
redirect $ url ++ decodeUtf8 (rawQueryString req)
|
redirect $ url ++ decodeUtf8 (rawQueryString req)
|
||||||
|
|
||||||
getOldLtsR :: [Text] -> Handler ()
|
getOldSnapshotBranchR :: SnapshotBranch -> [Text] -> Handler ()
|
||||||
getOldLtsR pieces = do
|
getOldSnapshotBranchR LtsBranch pieces = do
|
||||||
(x, y, pieces') <- case pieces of
|
(x, y, pieces') <- case pieces of
|
||||||
t:ts | Just suffix <- parseLtsSuffix t -> do
|
t:ts | Just suffix <- parseLtsSuffix t -> do
|
||||||
(x, y) <- case suffix of
|
(x, y) <- case suffix of
|
||||||
@ -44,14 +42,12 @@ getOldLtsR pieces = do
|
|||||||
let name = concat ["lts-", tshow x, ".", tshow y]
|
let name = concat ["lts-", tshow x, ".", tshow y]
|
||||||
redirectWithQueryText $ concatMap (cons '/') $ name : pieces'
|
redirectWithQueryText $ concatMap (cons '/') $ name : pieces'
|
||||||
|
|
||||||
getOldLtsMajorR :: LtsMajor -> [Text] -> Handler ()
|
getOldSnapshotBranchR (LtsMajorBranch x) pieces = do
|
||||||
getOldLtsMajorR (LtsMajor x) pieces = do
|
|
||||||
y <- newestLTSMajor x >>= maybe notFound return
|
y <- newestLTSMajor x >>= maybe notFound return
|
||||||
let name = concat ["lts-", tshow x, ".", tshow y]
|
let name = concat ["lts-", tshow x, ".", tshow y]
|
||||||
redirectWithQueryText $ concatMap (cons '/') $ name : pieces
|
redirectWithQueryText $ concatMap (cons '/') $ name : pieces
|
||||||
|
|
||||||
getOldNightlyR :: [Text] -> Handler ()
|
getOldSnapshotBranchR NightlyBranch pieces = do
|
||||||
getOldNightlyR pieces = do
|
|
||||||
(day, pieces') <- case pieces of
|
(day, pieces') <- case pieces of
|
||||||
t:ts | Just day <- fromPathPiece t -> return (day, ts)
|
t:ts | Just day <- fromPathPiece t -> return (day, ts)
|
||||||
_ -> do
|
_ -> do
|
||||||
|
|||||||
@ -11,10 +11,8 @@ getSitemapR :: Handler TypedContent
|
|||||||
getSitemapR = sitemap $ do
|
getSitemapR = sitemap $ do
|
||||||
priority 1.0 $ HomeR
|
priority 1.0 $ HomeR
|
||||||
|
|
||||||
priority 0.9 $ OldLtsR []
|
priority 0.9 $ OldSnapshotBranchR LtsBranch []
|
||||||
-- TODO: uncomment when this is presentable
|
priority 0.8 $ OldSnapshotBranchR NightlyBranch []
|
||||||
--priority 0.9 $ DownloadR
|
|
||||||
priority 0.8 $ OldNightlyR []
|
|
||||||
|
|
||||||
priority 0.7 $ AllSnapshotsR
|
priority 0.7 $ AllSnapshotsR
|
||||||
priority 0.7 $ PackageListR
|
priority 0.7 $ PackageListR
|
||||||
|
|||||||
@ -24,9 +24,10 @@ getAllSnapshotsR = do
|
|||||||
currentPageMay <- lookupGetParam "page"
|
currentPageMay <- lookupGetParam "page"
|
||||||
let currentPage :: Int
|
let currentPage :: Int
|
||||||
currentPage = fromMaybe 1 (currentPageMay >>= readMay)
|
currentPage = fromMaybe 1 (currentPageMay >>= readMay)
|
||||||
(totalCount, map entityVal -> snapshots) <- getSnapshots
|
totalCount <- countSnapshots Nothing
|
||||||
snapshotsPerPage
|
(map entityVal -> snapshots) <-
|
||||||
((fromIntegral currentPage - 1) * snapshotsPerPage)
|
getSnapshots Nothing snapshotsPerPage
|
||||||
|
((fromIntegral currentPage - 1) * snapshotsPerPage)
|
||||||
let groups = groupUp now' snapshots
|
let groups = groupUp now' snapshots
|
||||||
|
|
||||||
let isFirstPage = currentPage == 1
|
let isFirstPage = currentPage == 1
|
||||||
|
|||||||
@ -32,7 +32,7 @@ getStackageDiffR :: SnapName -> SnapName -> Handler Html
|
|||||||
getStackageDiffR name1 name2 = do
|
getStackageDiffR name1 name2 = do
|
||||||
Entity sid1 _ <- lookupSnapshot name1 >>= maybe notFound return
|
Entity sid1 _ <- lookupSnapshot name1 >>= maybe notFound return
|
||||||
Entity sid2 _ <- lookupSnapshot name2 >>= maybe notFound return
|
Entity sid2 _ <- lookupSnapshot name2 >>= maybe notFound return
|
||||||
snapNames <- map (snapshotName . entityVal) . snd <$> getSnapshots 0 0
|
(map (snapshotName . entityVal) -> snapNames) <- getSnapshots Nothing 0 0
|
||||||
let (ltsSnaps, nightlySnaps) = partition isLts $ reverse $ sort snapNames
|
let (ltsSnaps, nightlySnaps) = partition isLts $ reverse $ sort snapNames
|
||||||
snapDiff <- getSnapshotDiff sid1 sid2
|
snapDiff <- getSnapshotDiff sid1 sid2
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
|
|||||||
@ -34,9 +34,7 @@ module Stackage.Database
|
|||||||
, prettyNameShort
|
, prettyNameShort
|
||||||
, getSnapshotsForPackage
|
, getSnapshotsForPackage
|
||||||
, getSnapshots
|
, getSnapshots
|
||||||
, getLtsSnapshots
|
, countSnapshots
|
||||||
, getLtsMajorSnapshots
|
|
||||||
, getNightlySnapshots
|
|
||||||
, currentSchema
|
, currentSchema
|
||||||
, last5Lts5Nightly
|
, last5Lts5Nightly
|
||||||
, snapshotsJSON
|
, snapshotsJSON
|
||||||
@ -71,6 +69,7 @@ import System.IO.Temp
|
|||||||
import qualified Database.Esqueleto as E
|
import qualified Database.Esqueleto as E
|
||||||
import Data.Yaml (decode)
|
import Data.Yaml (decode)
|
||||||
import qualified Data.Aeson as A
|
import qualified Data.Aeson as A
|
||||||
|
import Types (SnapshotBranch(..))
|
||||||
|
|
||||||
currentSchema :: Int
|
currentSchema :: Int
|
||||||
currentSchema = 1
|
currentSchema = 1
|
||||||
@ -664,64 +663,44 @@ getSnapshotsForPackage pname = run $ do
|
|||||||
Nothing -> Nothing
|
Nothing -> Nothing
|
||||||
Just s -> Just (s, snapshotPackageVersion sp)
|
Just s -> Just (s, snapshotPackageVersion sp)
|
||||||
|
|
||||||
getSnapshots
|
-- | Count snapshots that belong to a specific SnapshotBranch
|
||||||
:: GetStackageDatabase m
|
countSnapshots :: (GetStackageDatabase m) => Maybe SnapshotBranch -> m Int
|
||||||
=> Int -- ^ limit
|
countSnapshots Nothing = run $ count ([] :: [Filter Snapshot])
|
||||||
-> Int -- ^ offset
|
countSnapshots (Just NightlyBranch) = run $ count ([] :: [Filter Nightly])
|
||||||
-> m (Int, [Entity Snapshot])
|
countSnapshots (Just LtsBranch) = run $ count ([] :: [Filter Lts])
|
||||||
getSnapshots l o = run $ (,)
|
countSnapshots (Just (LtsMajorBranch x)) = run $ count [LtsMajor ==. x]
|
||||||
<$> count ([] :: [Filter Snapshot])
|
|
||||||
<*> selectList
|
|
||||||
[]
|
|
||||||
[LimitTo l, OffsetBy o, Desc SnapshotCreated]
|
|
||||||
|
|
||||||
getLtsSnapshots :: GetStackageDatabase m
|
-- | Get snapshots that belong to a specific SnapshotBranch
|
||||||
=> Int -- ^ limit
|
getSnapshots :: (GetStackageDatabase m)
|
||||||
-> Int -- ^ offset
|
=> Maybe SnapshotBranch
|
||||||
-> m (Int, [Entity Snapshot])
|
-> Int -- ^ limit
|
||||||
getLtsSnapshots l o = run $ do
|
-> Int -- ^ offset
|
||||||
ltsCount <- count ([] :: [Filter Lts])
|
-> m [Entity Snapshot]
|
||||||
snapshots <- E.select $ E.from $
|
getSnapshots mBranch l o = run $ case mBranch of
|
||||||
\(lts `E.InnerJoin` snapshot) -> do
|
Nothing -> selectList [] [LimitTo l, OffsetBy o, Desc SnapshotCreated]
|
||||||
|
Just NightlyBranch ->
|
||||||
|
E.select $ E.from $ \(nightly `E.InnerJoin` snapshot) -> do
|
||||||
|
E.on $ nightly E.^. NightlySnap E.==. snapshot E.^. SnapshotId
|
||||||
|
E.orderBy [E.desc (nightly E.^. NightlyDay)]
|
||||||
|
E.limit $ fromIntegral l
|
||||||
|
E.offset $ fromIntegral o
|
||||||
|
pure snapshot
|
||||||
|
Just LtsBranch -> do
|
||||||
|
E.select $ E.from $ \(lts `E.InnerJoin` snapshot) -> do
|
||||||
E.on $ lts E.^. LtsSnap E.==. snapshot E.^. SnapshotId
|
E.on $ lts E.^. LtsSnap E.==. snapshot E.^. SnapshotId
|
||||||
E.orderBy [ E.desc (lts E.^. LtsMajor)
|
E.orderBy [ E.desc (lts E.^. LtsMajor)
|
||||||
, E.desc (lts E.^. LtsMinor) ]
|
, E.desc (lts E.^. LtsMinor) ]
|
||||||
E.limit $ fromIntegral l
|
E.limit $ fromIntegral l
|
||||||
E.offset $ fromIntegral o
|
E.offset $ fromIntegral o
|
||||||
return snapshot
|
pure snapshot
|
||||||
return (ltsCount, snapshots)
|
Just (LtsMajorBranch v) -> do
|
||||||
|
E.select $ E.from $ \(lts `E.InnerJoin` snapshot) -> do
|
||||||
getLtsMajorSnapshots :: GetStackageDatabase m
|
|
||||||
=> Int -- ^ Major version
|
|
||||||
-> Int -- ^ limit
|
|
||||||
-> Int -- ^ offset
|
|
||||||
-> m (Int, [Entity Snapshot])
|
|
||||||
getLtsMajorSnapshots v l o = run $ do
|
|
||||||
ltsCount <- count ([] :: [Filter Lts])
|
|
||||||
snapshots <- E.select $ E.from $
|
|
||||||
\(lts `E.InnerJoin` snapshot) -> do
|
|
||||||
E.on $ lts E.^. LtsSnap E.==. snapshot E.^. SnapshotId
|
E.on $ lts E.^. LtsSnap E.==. snapshot E.^. SnapshotId
|
||||||
E.orderBy [E.desc (lts E.^. LtsMinor)]
|
E.orderBy [E.desc (lts E.^. LtsMinor)]
|
||||||
E.where_ ((lts E.^. LtsMajor) E.==. (E.val v))
|
E.where_ ((lts E.^. LtsMajor) E.==. (E.val v))
|
||||||
E.limit $ fromIntegral l
|
E.limit $ fromIntegral l
|
||||||
E.offset $ fromIntegral o
|
E.offset $ fromIntegral o
|
||||||
return snapshot
|
pure snapshot
|
||||||
return (ltsCount, snapshots)
|
|
||||||
|
|
||||||
getNightlySnapshots :: GetStackageDatabase m
|
|
||||||
=> Int -- ^ limit
|
|
||||||
-> Int -- ^ offset
|
|
||||||
-> m (Int, [Entity Snapshot])
|
|
||||||
getNightlySnapshots l o = run $ do
|
|
||||||
nightlyCount <- count ([] :: [Filter Nightly])
|
|
||||||
snapshots <- E.select $ E.from $
|
|
||||||
\(nightly `E.InnerJoin` snapshot) -> do
|
|
||||||
E.on $ nightly E.^. NightlySnap E.==. snapshot E.^. SnapshotId
|
|
||||||
E.orderBy [E.desc (nightly E.^. NightlyDay)]
|
|
||||||
E.limit $ fromIntegral l
|
|
||||||
E.offset $ fromIntegral o
|
|
||||||
return snapshot
|
|
||||||
return (nightlyCount, snapshots)
|
|
||||||
|
|
||||||
last5Lts5Nightly :: GetStackageDatabase m => m [SnapName]
|
last5Lts5Nightly :: GetStackageDatabase m => m [SnapName]
|
||||||
last5Lts5Nightly = run $ do
|
last5Lts5Nightly = run $ do
|
||||||
|
|||||||
17
Types.hs
17
Types.hs
@ -11,14 +11,21 @@ import qualified Data.Text.Lazy.Builder as Builder
|
|||||||
import qualified Data.Text.Lazy as LText
|
import qualified Data.Text.Lazy as LText
|
||||||
import qualified Data.Text.Read as Reader
|
import qualified Data.Text.Read as Reader
|
||||||
|
|
||||||
newtype LtsMajor = LtsMajor Int
|
data SnapshotBranch = LtsMajorBranch Int
|
||||||
deriving (Eq, Read, Show)
|
| LtsBranch
|
||||||
instance PathPiece LtsMajor where
|
| NightlyBranch
|
||||||
toPathPiece (LtsMajor x) = "lts-" ++ tshow x
|
deriving (Eq, Read, Show)
|
||||||
|
instance PathPiece SnapshotBranch where
|
||||||
|
toPathPiece NightlyBranch = "nightly"
|
||||||
|
toPathPiece LtsBranch = "lts"
|
||||||
|
toPathPiece (LtsMajorBranch x) = "lts-" ++ tshow x
|
||||||
|
|
||||||
|
fromPathPiece "nightly" = Just NightlyBranch
|
||||||
|
fromPathPiece "lts" = Just LtsBranch
|
||||||
fromPathPiece t0 = do
|
fromPathPiece t0 = do
|
||||||
t1 <- stripPrefix "lts-" t0
|
t1 <- stripPrefix "lts-" t0
|
||||||
Right (x, "") <- Just $ Reader.decimal t1
|
Right (x, "") <- Just $ Reader.decimal t1
|
||||||
Just $ LtsMajor x
|
Just $ LtsMajorBranch x
|
||||||
|
|
||||||
newtype PackageName = PackageName { unPackageName :: Text }
|
newtype PackageName = PackageName { unPackageName :: Text }
|
||||||
deriving (Show, Read, Typeable, Eq, Ord, Hashable, PathPiece, ToMarkup, PersistField, IsString)
|
deriving (Show, Read, Typeable, Eq, Ord, Hashable, PathPiece, ToMarkup, PersistField, IsString)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
!/#LtsMajor/*Texts OldLtsMajorR GET
|
!/#SnapshotBranch/*Texts OldSnapshotBranchR GET
|
||||||
|
|
||||||
/static StaticR Static getStatic
|
/static StaticR Static getStatic
|
||||||
/reload WebsiteContentR GitRepo-WebsiteContent websiteContent
|
/reload WebsiteContentR GitRepo-WebsiteContent websiteContent
|
||||||
@ -32,9 +32,6 @@
|
|||||||
/package/#PackageName/snapshots PackageSnapshotsR GET
|
/package/#PackageName/snapshots PackageSnapshotsR GET
|
||||||
/package PackageListR GET
|
/package PackageListR GET
|
||||||
|
|
||||||
/lts/*Texts OldLtsR GET
|
|
||||||
/nightly/*Texts OldNightlyR GET
|
|
||||||
|
|
||||||
/authors AuthorsR GET
|
/authors AuthorsR GET
|
||||||
/install InstallR GET
|
/install InstallR GET
|
||||||
/older-releases OlderReleasesR GET
|
/older-releases OlderReleasesR GET
|
||||||
@ -47,9 +44,7 @@
|
|||||||
/download/#SupportedArch/#Text DownloadGhcLinksR GET
|
/download/#SupportedArch/#Text DownloadGhcLinksR GET
|
||||||
|
|
||||||
/feed FeedR GET
|
/feed FeedR GET
|
||||||
!/feed/#LtsMajor LtsMajorFeedR GET
|
/feed/#SnapshotBranch BranchFeedR GET
|
||||||
/feed/lts LtsFeedR GET
|
|
||||||
/feed/nightly NightlyFeedR GET
|
|
||||||
|
|
||||||
/stack DownloadStackListR GET
|
/stack DownloadStackListR GET
|
||||||
/stack/#Text DownloadStackR GET
|
/stack/#Text DownloadStackR GET
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user