From 07e9f9a213eff05ace1aaf47eb2ed42a720b5a03 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 17 Aug 2014 23:01:25 +0200 Subject: [PATCH] reworked image uploareworked image upload Please enter the commit message for your changes. Lines starting --- Handler/Upload.hs | 11 +++++++---- templates/default-layout.hamlet | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Handler/Upload.hs b/Handler/Upload.hs index 66e913d..eb32ada 100644 --- a/Handler/Upload.hs +++ b/Handler/Upload.hs @@ -37,7 +37,7 @@ postUploadR = do ((result, uploadWidget), enctype) <- runFormPost (uploadForm userId) case result of FormSuccess temp -> do - path <- writeOnDrive $ tempMediumFile temp + path <- writeOnDrive (tempMediumFile temp) userId (tempMediumAlbum temp) medium <- return $ Medium (tempMediumTitle temp) path @@ -56,10 +56,13 @@ postUploadR = do setMessage "You need to be logged in" redirect $ LoginR -writeOnDrive :: FileInfo -> Handler FilePath -writeOnDrive file = do +writeOnDrive :: FileInfo -> UserId -> AlbumId -> Handler FilePath +writeOnDrive file userId albumId = do filename <- return $ fileName file - path <- return $ "static" (unpack filename) + path <- return $ "data" + (unpack $ extractKey userId) + (unpack $ extractKey albumId) + (unpack filename) liftIO $ fileMove file path return path diff --git a/templates/default-layout.hamlet b/templates/default-layout.hamlet index 7f7f940..281180b 100644 --- a/templates/default-layout.hamlet +++ b/templates/default-layout.hamlet @@ -7,6 +7,8 @@ Logout
  • Create album +
  • + Upload image $nothing
  • Login