diff --git a/Handler/Commons.hs b/Handler/Commons.hs index 3d352b2..52d7fab 100755 --- a/Handler/Commons.hs +++ b/Handler/Commons.hs @@ -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 diff --git a/Handler/MediumSettings.hs b/Handler/MediumSettings.hs index 1619bd9..931c890 100755 --- a/Handler/MediumSettings.hs +++ b/Handler/MediumSettings.hs @@ -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 diff --git a/config/routes b/config/routes index a34d442..995913e 100755 --- a/config/routes +++ b/config/routes @@ -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 diff --git a/templates/mediumSettings.hamlet b/templates/mediumSettings.hamlet index ed33fe8..1ab2485 100755 --- a/templates/mediumSettings.hamlet +++ b/templates/mediumSettings.hamlet @@ -4,8 +4,11 @@ $newline always
^{mediumSettingsWidget} - - Delete this image +