restricting uploadable filetypes
This commit is contained in:
parent
90182768f1
commit
485fe73fde
2 changed files with 52 additions and 35 deletions
|
@ -11,6 +11,7 @@ import Control.Monad.Trans.Resource
|
||||||
import Foreign
|
import Foreign
|
||||||
import Foreign.C.Types
|
import Foreign.C.Types
|
||||||
import Foreign.C.String
|
import Foreign.C.String
|
||||||
|
import Helper
|
||||||
|
|
||||||
data TempMedium = TempMedium
|
data TempMedium = TempMedium
|
||||||
{ tempMediumTitle :: Text
|
{ tempMediumTitle :: Text
|
||||||
|
@ -45,7 +46,10 @@ postUploadR = do
|
||||||
((result, uploadWidget), enctype) <- runFormPost (uploadForm userId)
|
((result, uploadWidget), enctype) <- runFormPost (uploadForm userId)
|
||||||
case result of
|
case result of
|
||||||
FormSuccess temp -> do
|
FormSuccess temp -> do
|
||||||
path <- writeOnDrive (tempMediumFile temp) userId (tempMediumAlbum temp)
|
fil <- return $ tempMediumFile temp
|
||||||
|
case (fileContentType fil) `elem` acceptedTypes of
|
||||||
|
True -> do
|
||||||
|
path <- writeOnDrive fil userId (tempMediumAlbum temp)
|
||||||
thumbPath <- generateThumb path userId (tempMediumAlbum temp)
|
thumbPath <- generateThumb path userId (tempMediumAlbum temp)
|
||||||
inAlbumId <- return $ tempMediumAlbum temp
|
inAlbumId <- return $ tempMediumAlbum temp
|
||||||
medium <- return $ Medium
|
medium <- return $ Medium
|
||||||
|
@ -63,6 +67,9 @@ postUploadR = do
|
||||||
runDB $ update inAlbumId [AlbumContent =. newMediaList]
|
runDB $ update inAlbumId [AlbumContent =. newMediaList]
|
||||||
setMessage "Image succesfully uploaded"
|
setMessage "Image succesfully uploaded"
|
||||||
redirect $ HomeR
|
redirect $ HomeR
|
||||||
|
_ -> do
|
||||||
|
setMessage "This filetype is not supported"
|
||||||
|
redirect $ UploadR
|
||||||
_ -> do
|
_ -> do
|
||||||
setMessage "There was an error uploading the file"
|
setMessage "There was an error uploading the file"
|
||||||
redirect $ UploadR
|
redirect $ UploadR
|
||||||
|
@ -117,7 +124,10 @@ postDirectUploadR albumId = do
|
||||||
((result, dUploadWidget), enctype) <- runFormPost (dUploadForm userId albumId)
|
((result, dUploadWidget), enctype) <- runFormPost (dUploadForm userId albumId)
|
||||||
case result of
|
case result of
|
||||||
FormSuccess temp -> do
|
FormSuccess temp -> do
|
||||||
path <- writeOnDrive (tempMediumFile temp) userId albumId
|
fil <- return $ tempMediumFile temp
|
||||||
|
case (fileContentType fil) `elem` acceptedTypes of
|
||||||
|
True -> do
|
||||||
|
path <- writeOnDrive fil userId albumId
|
||||||
thumbPath <- generateThumb path ownerId albumId
|
thumbPath <- generateThumb path ownerId albumId
|
||||||
medium <- return $ Medium
|
medium <- return $ Medium
|
||||||
(tempMediumTitle temp)
|
(tempMediumTitle temp)
|
||||||
|
@ -134,6 +144,9 @@ postDirectUploadR albumId = do
|
||||||
runDB $ update albumId [AlbumContent =. newMediaList]
|
runDB $ update albumId [AlbumContent =. newMediaList]
|
||||||
setMessage "Image successfully uploaded"
|
setMessage "Image successfully uploaded"
|
||||||
redirect $ AlbumR albumId
|
redirect $ AlbumR albumId
|
||||||
|
_ -> do
|
||||||
|
setMessage "This filetype is not supported"
|
||||||
|
redirect $ DirectUploadR albumId
|
||||||
_ -> do
|
_ -> do
|
||||||
setMessage "There was an error uploading the file"
|
setMessage "There was an error uploading the file"
|
||||||
redirect $ DirectUploadR albumId
|
redirect $ DirectUploadR albumId
|
||||||
|
|
|
@ -11,6 +11,7 @@ module Helper
|
||||||
, sendMail
|
, sendMail
|
||||||
, generateString
|
, generateString
|
||||||
, removeItem
|
, removeItem
|
||||||
|
, acceptedTypes
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
|
@ -117,3 +118,6 @@ removeItem _ [] = []
|
||||||
removeItem x (y:ys)
|
removeItem x (y:ys)
|
||||||
| x == y = removeItem x ys
|
| x == y = removeItem x ys
|
||||||
| otherwise = y : removeItem x ys
|
| otherwise = y : removeItem x ys
|
||||||
|
|
||||||
|
acceptedTypes :: [T.Text]
|
||||||
|
acceptedTypes = ["image/jpeg", "image/png", "image/x-ms-bmp", "image/x-bmp", "image/bmp", "image/tiff", "image/tiff-fx"]
|
||||||
|
|
Loading…
Reference in a new issue