now working

This commit is contained in:
nek0 2016-10-23 00:18:13 +02:00
parent 22f4cdce73
commit ac2cb03de8
4 changed files with 27 additions and 8 deletions

View file

@ -108,23 +108,35 @@ deleteMedium mId medium = do
moveMedium :: Medium -> MediumId -> AlbumId -> Handler ()
moveMedium med mId destId = do
$(logError) "getting destination"
dest <- runDB $ getJust destId
-- remove reference
$(logError) "removing reference"
removeReference mId $ mediumAlbum med
-- move physical Files
let filen = show $ length (albumContent dest) + 1
ext = takeExtension $ mediumPath med
nPath = "static" </> "data" </> T.unpack (extractKey $ albumOwner dest) </> T.unpack (extractKey destId) </> filen ++ ext
nThumb = takeBaseName nPath ++ "_thumb.jpg"
nPrev = takeBaseName nPath ++ "_preview.jpg"
liftIO $ renameFile (mediumPath med) nPath
liftIO $ renameFile (mediumThumb med) nThumb
liftIO $ renameFile (mediumPreview med) nPrev
prefix = "static" </> "data" </> T.unpack (extractKey $ albumOwner dest) </> T.unpack (extractKey destId)
nPath = prefix </> filen ++ ext
nThumb = prefix </> takeBaseName nPath ++ "_thumb.jpg"
nPrev = prefix </> takeBaseName nPath ++ "_preview.jpg"
$(logError) $ T.pack $ "copyFile" ++ nPath
liftIO $ copyFile (L.tail $ mediumPath med) nPath
liftIO $ copyFile (L.tail $ mediumThumb med) nThumb
liftIO $ copyFile (L.tail $ mediumPreview med) nPrev
-- remove physical files
$(logError) "removeFile"
mapM_ (liftIO . removeFile . normalise . L.tail)
[ mediumPath med
, mediumThumb med
, mediumPreview med
]
-- chenge filenames in database
runDB $ update mId
[ MediumPath =. '/' : nPath
, MediumThumb =. '/' : nThumb
, MediumPreview =. '/' : nPrev
, MediumAlbum =. destId
]
-- create new references
let newMediaList = mId : albumContent dest

View file

@ -147,6 +147,9 @@ postMediumMoveR mId = do
moveMedium medium mId aId
setMessage "Medium successfully moved"
redirect $ MediumR mId
Left (err, route) -> do
setMessage err
redirect route
mediumMoveForm :: Medium -> AForm Handler AlbumId
mediumMoveForm medium = id

View file

@ -36,6 +36,7 @@
/album/#AlbumId/delete AlbumDeleteR GET POST
/medium/#MediumId/settings MediumSettingsR GET POST
/medium/#MediumId/delete MediumDeleteR GET POST
/medium/#MediumId/move MediumMoveR GET POST
/comment/#CommentId/reply CommentReplyR GET POST
/comment/#CommentId/delcom CommentDeleteR GET POST
/reactivate ReactivateR GET POST

View file

@ -4,8 +4,11 @@ $newline always
<form method="post" enctype=#{enctype}>
^{mediumSettingsWidget}
<a href=@{MediumDeleteR mediumId}>Delete this image
<ul>
<li>
<a href=@{MediumDeleteR mediumId}>Delete this image
<li>
<a href=@{MediumMoveR mediumId}>Move this image
<style type="text/css">
body{background-image: url('/static/css/images/overlay.png'), -webkit-linear-gradient(top, rgba(0,0,0,0) 75%, rgba(0,0,0,0.65)), url('@{StaticR $ StaticRoute (drop 2 $ map T.pack $ splitDirectories $ mediumPath medium) []}');background-attachment:fixed;background-image: url('/static/css/images/overlay.png'), -moz-linear-gradient(center top , transparent 75%, rgba(0, 0, 0, 0.65)), url('@{StaticR $ StaticRoute (drop 2 $ map T.pack $ splitDirectories $ mediumPath medium) []}');}