Skip to content

Commit

Permalink
Made it compile and work again.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastiaan Visser committed Mar 7, 2010
1 parent 94cc9f2 commit 3d35978
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 35 deletions.
41 changes: 17 additions & 24 deletions src/Network/Orchid/Core/Handler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ where

import Control.Applicative
import Control.Monad.Trans
import Control.Concurrent.STM
import Control.Monad.State
import Data.Record.Label
import Misc.Commons
import Data.FileStore hiding (NotFound)
import Network.Orchid.Core.Format
import Network.Orchid.Core.Liaison
Expand All @@ -25,8 +21,6 @@ import Network.Salvia.Handlers
import Network.Salvia.Httpd
import Paths_orchid

-------- main entry point -----------------------------------------------------

data FileStoreType = Git | Darcs

mkFileStore :: FileStoreType -> FilePath -> FileStore
Expand All @@ -41,8 +35,12 @@ hRepository
hRepository kind repo dir =
let fs = mkFileStore kind repo in
hPath "/search" (post (hWikiSearch fs))
$ hPrefix "/_" (hFileSystem (repo /+ "_"))
$ hFileTypeDispatcher hDirectoryResource ( const $ hWithoutDir repo $ hWikiREST dir fs) repo
$ hPrefix "/_images" (hFileSystem (repo /+ "_images"))
$ hPrefix "/_cache" (hFileSystem (repo /+ "_cache"))
$ hFileTypeDispatcher
hDirectoryResource
(\_ -> hWithoutDir repo (hWikiREST dir fs))
repo

hViewer
:: (MonadIO m, HttpM' m, SendM m, QueueM m, BodyM Request m, Alternative m)
Expand All @@ -62,7 +60,7 @@ hWiki kind repo dir = do
hWikiCustomViewer
:: (LoginM m p, Alternative m, QueueM m, SendM m, MonadIO m, HttpM' m, BodyM Request m)
=> FilePath -> FileStoreType -> FilePath -> FilePath -> m ()
hWikiCustomViewer viewerDir kind repo dir =
hWikiCustomViewer viewerDir kind repo dir =
hPrefix "/data"
(hRepository kind repo dir)
(authHandlers (hViewer viewerDir))
Expand All @@ -77,37 +75,32 @@ authHandlers =
]

ok :: (HttpM Response m, SendM m) => m ()
ok = hCustomError OK "ok dan!!!!"
ok = hCustomError OK "ok"

post :: (HttpM Response m, SendM m, HttpM Request m) => m () -> m ()
post h = hMethod POST h (hError NotFound)

-------- REST interface -------------------------------------------------------

-- The wiki module will act as a REST interface by using the MethodRouter
-- handler to dispatch on the HTTP request method.

forbidden :: (HttpM Response m, SendM m) => m ()
forbidden = hCustomError Forbidden "No authorized to perform this action"

hWikiREST
:: (HttpM' m, BodyM Request m, SendM m, MonadIO m, LoginM m p)
=> FilePath -> FileStore -> m ()
hWikiREST dir fs =
hUri $ \uri ->
previewHandlers fs dir uri
. actionHandlers fs dir uri
hUri $ \u ->
previewHandlers u
. actionHandlers u
$ hError BadRequest
where

previewHandlers fs dir uri = hPathRouter
$ map (\ext -> ("/preview." ++ ext, hWikiRetrieve fs dir True uri))
previewHandlers u = hPathRouter
$ map (\ext -> ("/preview." ++ ext, hWikiRetrieve fs dir True u))
(map postfix wikiFormats)

actionHandlers fs dir uri =
actionHandlers u =
hMethodRouter [
(GET, hWikiRetrieve fs dir False uri )
, (PUT, authorized (Just "edit") forbidden (\user -> hWikiStore fs user uri))
, (DELETE, authorized (Just "delete") forbidden (\user -> hWikiDeleteOrRename fs user uri))
(GET, hWikiRetrieve fs dir False u )
, (PUT, authorized (Just "edit") forbidden (\user -> hWikiStore fs user u))
, (DELETE, authorized (Just "delete") forbidden (\user -> hWikiDeleteOrRename fs user u))
]

22 changes: 11 additions & 11 deletions src/Network/Orchid/Core/Liaison.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ module Network.Orchid.Core.Liaison (
) where

import Control.Applicative
import Control.Category
import Control.Exception.Extensible
import Control.Monad.State hiding (get)
import Data.Encoding
import Data.Encoding.UTF8
import Data.FileStore hiding (NotFound)
import Data.List hiding (delete)
import Data.Record.Label
import Misc.Commons
import Network.Orchid.Core.Format (WikiFormat (..), Output (..))
import Network.Orchid.FormatRegister
import Network.Protocol.Http
import Network.Protocol.Uri
import Network.Protocol.Uri.Parser ()
import Network.Salvia.Handlers
import Network.Salvia.Httpd hiding (body)
import qualified Data.ByteString.Lazy as B
import Prelude hiding ((.), id)
import Control.Category
import Safe
import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString.Lazy.UTF8 as U

-------- showing wiki documents -----------------------------------------------

Expand Down Expand Up @@ -60,7 +60,7 @@ hWikiRetrieve filestore workDir b u = do
Just s -> do
b' <- liftIO $ (handler fmt) filestore workDir src s
(body', enc) <- return $ case b' of
TextOutput s' -> (encodeLazyByteString UTF8 s', Just "utf-8")
TextOutput s' -> (U.fromString s', Just "utf-8")
BinaryOutput bs -> (bs, Nothing)

response $
Expand All @@ -82,7 +82,7 @@ hWikiDeleteOrRename filestore user u = do
then hCustomError BadRequest errEmptyRev
else do
doc <- hRequestBodyStringUTF8
let aut = Author (get username user) "test" --(email user)
let aut = Author (get username user) (get email user)
src = dropWhile (=='/') $ set extension Nothing $ get path u
liftIO $ rename filestore src doc aut rev

Expand All @@ -100,7 +100,7 @@ hWikiStore filestore user u = do

True -> hCustomError BadRequest errEmptyRev
False -> liftIO $ do
let aut = Author (get username user) "test" --(email user)
let aut = Author (get username user) (get email user)
src = dropWhile (=='/') $ set extension Nothing $ get path u
save filestore src aut rev doc

Expand All @@ -122,9 +122,9 @@ hWikiSearch filestore = do
getSearchInfo :: Parameters -> Maybe (String, Bool, Bool, Bool)
getSearchInfo p = do
patterns <- "patterns" `lookup` p >>= id
wholewords <- "wholewords" `lookup` p >>= id >>= safeRead
matchall <- "matchall" `lookup` p >>= id >>= safeRead
ignorecase <- "ignorecase" `lookup` p >>= id >>= safeRead
wholewords <- "wholewords" `lookup` p >>= id >>= readMay
matchall <- "matchall" `lookup` p >>= id >>= readMay
ignorecase <- "ignorecase" `lookup` p >>= id >>= readMay
return (patterns, wholewords, matchall, ignorecase)

showMatch :: SearchMatch -> String
Expand Down

0 comments on commit 3d35978

Please sign in to comment.