PGF service: new command: download

This makes it possible to download PGF files from servers where the PGF service
is installed.

I am also considering making commmand=download the default instead of
command=grammar.
This commit is contained in:
hallgren
2013-01-09 13:28:45 +00:00
parent ccc3d6be0d
commit eb21f73fd3
2 changed files with 13 additions and 8 deletions

View File

@@ -51,11 +51,12 @@ cgiMain' cache path =
do pgf <- liftIO $ readCache cache path
command <- liftM (maybe "grammar" (urlDecodeUnicode . UTF8.decodeString))
(getInput "command")
pgfMain pgf command
pgfMain path pgf command
pgfMain :: PGF -> String -> CGI CGIResult
pgfMain pgf command =
pgfMain :: FilePath -> PGF -> String -> CGI CGIResult
pgfMain path pgf command =
case command of
"download" -> outputBinary =<< liftIO (BS.readFile path)
"parse" -> outputJSONP =<< doParse pgf `fmap` getText `ap` getCat `ap` getFrom `ap` getLimit
"complete" -> outputJSONP =<< doComplete pgf `fmap` getText `ap` getCat `ap` getFrom `ap` getLimit
"linearize" -> outputJSONP =<< doLinearize pgf `fmap` getTree `ap` getTo