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
|
2016-12-19 02:18:06 +00:00
|
|
|
import Text.Blaze (toMarkup)
|
2015-02-12 04:25:15 +00:00
|
|
|
import System.FilePath
|
2015-09-26 09:15:20 +00:00
|
|
|
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
|
2017-04-26 19:43:22 +00:00
|
|
|
ownerSlug = userSlug owner
|
|
|
|
musername <- maybeAuthId
|
|
|
|
presence <- case musername of
|
|
|
|
Just username -> do
|
|
|
|
(Just (Entity uId _)) <- runDB $ getBy $ UniqueUser username
|
|
|
|
return $ (username == ownerName) || (uId `elem` albumShares album)
|
2014-08-18 04:07:10 +00:00
|
|
|
Nothing ->
|
2014-12-06 03:39:24 +00:00
|
|
|
return False
|
2014-08-18 11:17:54 +00:00
|
|
|
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)
|
2015-09-26 09:15:20 +00:00
|
|
|
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
|
2016-12-19 01:55:51 +00:00
|
|
|
|
|
|
|
getBeautyAlbumR :: T.Text -> T.Text -> Handler Html
|
|
|
|
getBeautyAlbumR ownerName albumName = do
|
|
|
|
tempOwner <- runDB $ getBy $ UniqueUser ownerName
|
|
|
|
case tempOwner of
|
|
|
|
Just (Entity ownerId _) -> do
|
2016-12-19 02:18:06 +00:00
|
|
|
tempAlbum <- runDB $ selectFirst [AlbumTitle ==. albumName, AlbumOwner ==. ownerId] []
|
2016-12-19 01:55:51 +00:00
|
|
|
case tempAlbum of
|
|
|
|
Just (Entity albumId _) ->
|
|
|
|
getAlbumR albumId
|
|
|
|
Nothing -> do
|
2016-12-19 02:18:06 +00:00
|
|
|
setMessage $ toMarkup $ "This user has no album named " `T.append` albumName
|
2016-12-19 01:55:51 +00:00
|
|
|
redirect $ UserR ownerName
|
|
|
|
Nothing -> do
|
|
|
|
setMessage "This user does not exist"
|
|
|
|
redirect HomeR
|