aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2020-03-01 18:10:12 +0100
committerDaniel Schadt <kingdread@gmx.de>2020-03-01 18:10:12 +0100
commit7f11cf1617aed8930598d7bd908ee1625cbc97f7 (patch)
tree2f799200a78e04817ed4b084255ee8479cc06371 /src
parent76771f6e87d23972b0e590e9811de5c1a4d4e5c7 (diff)
downloadsimghost-7f11cf1617aed8930598d7bd908ee1625cbc97f7.tar.gz
simghost-7f11cf1617aed8930598d7bd908ee1625cbc97f7.tar.bz2
simghost-7f11cf1617aed8930598d7bd908ee1625cbc97f7.zip
rewrite imgHostMain
The right-drift was not nice to look at, so we're now doing the dispatch using a small helper method.
Diffstat (limited to 'src')
-rw-r--r--src/Lib.hs29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/Lib.hs b/src/Lib.hs
index 2b5f0a1..5a48f3f 100644
--- a/src/Lib.hs
+++ b/src/Lib.hs
@@ -291,12 +291,23 @@ handleUpload = do
-- Depending on the given parameters, this either dispatches to
-- 'handleCleanup', 'handleUpload' or just returns the 'indexPage'.
imgHostMain :: App CGIResult
-imgHostMain = do
- cleanup <- getInput "cleanup"
- case cleanup of
- Just _ -> handleCleanup
- Nothing -> do
- method <- requestMethod
- case method of
- "POST" -> handleUpload
- _ -> output indexPage
+imgHostMain = dispatch [ (doCleanup, handleCleanup)
+ , (doUpload, handleUpload)
+ , (doDefault, output indexPage)
+ ]
+ where
+ dispatch :: [(App Bool, App CGIResult)] -> App CGIResult
+ dispatch ((c, a):as) = do
+ take_that <- c
+ if take_that then a
+ else dispatch as
+ dispatch [] = do
+ setStatus 500 "Internal Server Error"
+ output "No dispatch could be done :("
+
+ doCleanup :: App Bool
+ doCleanup = isJust <$> getInput "cleanup"
+ doUpload :: App Bool
+ doUpload = ("POST" ==) <$> requestMethod
+ doDefault :: App Bool
+ doDefault = return True