eidolon/Handler/Album.hs

51 lines
2 KiB
Haskell
Raw Normal View History

2015-01-18 19:44:41 +00:00
-- eidolon -- A simple gallery in Haskell and Yesod
-- Copyright (C) 2015 Amedeo Molnár
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Affero General Public License as published
-- by the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Affero General Public License for more details.
--
-- You should have received a copy of the GNU Affero General Public License
2015-01-21 09:00:18 +00:00
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
2015-01-18 19:44:41 +00:00
2014-08-18 01:09:37 +00:00
module Handler.Album where
import Import
2014-09-24 21:03:18 +00:00
import qualified Data.Text as T
import System.FilePath
import Yesod.RssFeed
import Yesod.AtomFeed
2014-08-18 01:09:37 +00:00
2014-08-18 04:07:10 +00:00
getAlbumR :: AlbumId -> Handler Html
getAlbumR albumId = do
tempAlbum <- runDB $ get albumId
case tempAlbum of
Just album -> do
2015-09-14 16:54:46 +00:00
let ownerId = albumOwner album
2014-08-18 04:07:10 +00:00
owner <- runDB $ getJust ownerId
2015-09-14 16:54:46 +00:00
let ownerName = userName owner
let ownerSlug = userSlug owner
2014-08-18 04:07:10 +00:00
msu <- lookupSession "userId"
presence <- case msu of
Just tempUserId -> do
2015-09-14 16:54:46 +00:00
let userId = getUserIdFromText tempUserId
return $ (userId == ownerId) || (userId `elem` albumShares album)
2014-08-18 04:07:10 +00:00
Nothing ->
return False
-- media <- mapM (\a -> runDB $ getJust a) (albumContent album)
media <- runDB $ selectList [MediumAlbum ==. albumId] [Desc MediumTime]
2014-08-18 04:07:10 +00:00
defaultLayout $ do
2015-09-14 16:54:46 +00:00
setTitle $ toHtml ("Eidolon :: Album " `T.append` albumTitle album)
rssLink (AlbumFeedRssR albumId) $ "Album feed of album " `T.append` albumTitle album
atomLink (AlbumFeedAtomR albumId) $ "Album feed of album " `T.append` albumTitle album
2014-08-18 04:07:10 +00:00
$(widgetFile "album")
Nothing -> do
setMessage "This album does not exist"
2015-09-14 16:54:46 +00:00
redirect HomeR