mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-06 01:32:50 -06:00
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:
@@ -3,9 +3,8 @@ module FastCGIUtils (--initFastCGI, loopFastCGI,
|
|||||||
throwCGIError, handleCGIErrors,
|
throwCGIError, handleCGIErrors,
|
||||||
stderrToFile,logError,
|
stderrToFile,logError,
|
||||||
outputJSONP,outputEncodedJSONP,
|
outputJSONP,outputEncodedJSONP,
|
||||||
outputPNG,
|
outputPNG,outputBinary,
|
||||||
outputHTML,
|
outputHTML,outputPlain,
|
||||||
outputPlain,
|
|
||||||
splitBy) where
|
splitBy) where
|
||||||
|
|
||||||
import Control.Concurrent
|
import Control.Concurrent
|
||||||
@@ -177,14 +176,19 @@ outputPNG x = do
|
|||||||
setHeader "Content-Type" "image/png"
|
setHeader "Content-Type" "image/png"
|
||||||
outputFPS x
|
outputFPS x
|
||||||
|
|
||||||
|
outputBinary :: BS.ByteString -> CGI CGIResult
|
||||||
|
outputBinary x = do
|
||||||
|
setHeader "Content-Type" "application/binary"
|
||||||
|
outputFPS x
|
||||||
|
|
||||||
outputHTML :: String -> CGI CGIResult
|
outputHTML :: String -> CGI CGIResult
|
||||||
outputHTML x = do
|
outputHTML x = do
|
||||||
setHeader "Content-Type" "text/html"
|
setHeader "Content-Type" "text/html; charset=utf-8"
|
||||||
outputStrict $ UTF8.encodeString x
|
outputStrict $ UTF8.encodeString x
|
||||||
|
|
||||||
outputPlain :: String -> CGI CGIResult
|
outputPlain :: String -> CGI CGIResult
|
||||||
outputPlain x = do
|
outputPlain x = do
|
||||||
setHeader "Content-Type" "text/plain"
|
setHeader "Content-Type" "text/plain; charset=utf-8"
|
||||||
outputStrict $ UTF8.encodeString x
|
outputStrict $ UTF8.encodeString x
|
||||||
|
|
||||||
outputStrict :: String -> CGI CGIResult
|
outputStrict :: String -> CGI CGIResult
|
||||||
|
|||||||
@@ -51,11 +51,12 @@ cgiMain' cache path =
|
|||||||
do pgf <- liftIO $ readCache cache path
|
do pgf <- liftIO $ readCache cache path
|
||||||
command <- liftM (maybe "grammar" (urlDecodeUnicode . UTF8.decodeString))
|
command <- liftM (maybe "grammar" (urlDecodeUnicode . UTF8.decodeString))
|
||||||
(getInput "command")
|
(getInput "command")
|
||||||
pgfMain pgf command
|
pgfMain path pgf command
|
||||||
|
|
||||||
pgfMain :: PGF -> String -> CGI CGIResult
|
pgfMain :: FilePath -> PGF -> String -> CGI CGIResult
|
||||||
pgfMain pgf command =
|
pgfMain path pgf command =
|
||||||
case command of
|
case command of
|
||||||
|
"download" -> outputBinary =<< liftIO (BS.readFile path)
|
||||||
"parse" -> outputJSONP =<< doParse pgf `fmap` getText `ap` getCat `ap` getFrom `ap` getLimit
|
"parse" -> outputJSONP =<< doParse pgf `fmap` getText `ap` getCat `ap` getFrom `ap` getLimit
|
||||||
"complete" -> outputJSONP =<< doComplete 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
|
"linearize" -> outputJSONP =<< doLinearize pgf `fmap` getTree `ap` getTo
|
||||||
|
|||||||
Reference in New Issue
Block a user