git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

Commit 72e95872 authored by Bryan Richter's avatar Bryan Richter

Remove image upload

parent 1f176419
......@@ -56,7 +56,6 @@ library
Handler.BuildFeed
Handler.Common
Handler.HonorPledge
Handler.Image
Handler.Invitation
Handler.JsLicenses
Handler.MarkdownTutorial
......
......@@ -85,18 +85,9 @@
/js-license LegacyJsLicenseR GET
--
-- ### EXISTING STUFF (NOT NEW FOR ALPHA)
-- ## Browsing users and projects
--
-- Miscellaneous
/tutorial/markdown MarkdownTutorialR GET
/img/!upload UploadImageR GET POST
/img/!name/#UnnamedImageId NameImageR GET POST
/img/#Text ImageR GET
/img/#Text/meta ImageMetaR GET
-- User
/u UsersR GET
......
......@@ -39,10 +39,8 @@ import Widgets.Navbar
import Handler.BuildFeed
import Handler.Common
import Handler.HonorPledge
import Handler.Image
import Handler.Invitation
import Handler.JsLicenses
import Handler.MarkdownTutorial
import Handler.NewDesign
import Handler.PostLogin
import Handler.Project
......
{-# LANGUAGE RecordWildCards #-}
module Handler.Image where
import Import
import Control.Monad.Trans.Resource
import Data.Conduit
import Data.Text.Encoding
import Yesod.Core.Types
import qualified Data.Conduit.List as CL
import View.Time
getImageR :: Text -> Handler TypedContent
getImageR image_handle = do
Entity _ Image{..} <- runYDB $ getBy404 $ UniqueImageHandle image_handle
respond imageFormat imageData
getImageMetaR :: Text -> Handler Html
getImageMetaR image_handle = do
Entity _ Image{..} <- runYDB $ getBy404 $ UniqueImageHandle image_handle
defaultLayout $(widgetFile "image_metadata")
uploadForm :: Form (Text, FileInfo)
uploadForm = renderBootstrap3 BootstrapBasicForm $ (,)
<$> areq textField "Image Name" Nothing
<*> fileAFormReq "Image File"
getUploadImageR :: Handler Html
getUploadImageR = do
_ <- requireAuthId
(form, enctype) <- generateFormPost uploadForm
defaultLayout $(widgetFile "upload_image")
postUploadImageR :: Handler Html
postUploadImageR = do
user_id <- requireAuthId
((result, _), _) <- runFormPost uploadForm
now <- liftIO getCurrentTime
case result of
FormMissing -> error "form missing"
FormFailure err -> error $ "error processing form:\n" ++ unlines (map (('\t':) . show) err)
FormSuccess (name, FileInfo{..}) -> do
contents <- liftIO $ runResourceT $ fileSourceRaw $$ CL.foldMap id
maybe_image_id <- runDB $ insertUnique $ Image now user_id Nothing name Nothing (encodeUtf8 fileContentType) contents
case maybe_image_id of
Just _ -> redirect $ ImageMetaR name
Nothing -> do
setMessage "that name is already taken, try another"
unnamed_image_id <- runYDB $ insert $ UnnamedImage now user_id Nothing (Just name) Nothing (encodeUtf8 fileContentType) contents
redirect $ NameImageR unnamed_image_id
nameImageForm :: Maybe Text -> Form Text
nameImageForm = renderBootstrap3 BootstrapBasicForm . areq textField "New Image Name"
nameImage :: Text -> UnnamedImage -> Image
nameImage name (UnnamedImage ts uploader project _ origin format contents) = Image ts uploader project name origin format contents
getNameImageR :: UnnamedImageId -> Handler Html
getNameImageR unnamed_image_id = do
viewer_id <- requireAuthId
UnnamedImage{..} <- runYDB $ get404 unnamed_image_id
when (viewer_id /= unnamedImageUploader) $ permissionDenied "you did not upload this image"
(form, enctype) <- generateFormPost $ nameImageForm unnamedImageName
defaultLayout $(widgetFile "name_image")
postNameImageR :: UnnamedImageId -> Handler Html
postNameImageR unnamed_image_id = do
viewer_id <- requireAuthId
unnamed_image@UnnamedImage{..} <- runYDB $ get404 unnamed_image_id
when (viewer_id /= unnamedImageUploader) $ permissionDenied "you did not upload this image"
((result, _), _) <- runFormPost $ nameImageForm unnamedImageName
case result of
FormMissing -> error "form missing"
FormFailure err -> error $ "error processing form:\n" ++ unlines (map (('\t':) . show) err)
FormSuccess name -> do
maybe_image_id <- runDB $ insertUnique $ nameImage name unnamed_image
case maybe_image_id of
Just _ -> redirect $ ImageMetaR name
Nothing -> do
setMessage "that name is also already taken, try another"
runYDB $ update $ \ui -> do
where_ $ ui ^. UnnamedImageId ==. val unnamed_image_id
set ui [ UnnamedImageName =. val (Just name) ]
redirect $ NameImageR unnamed_image_id
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment