Drop text format dependency
This commit is contained in:
parent
0e4bb4024d
commit
4040f8e1f7
@ -33,7 +33,7 @@ executable breve
|
|||||||
Spock, blaze-html, http-types,
|
Spock, blaze-html, http-types,
|
||||||
wai, wai-middleware-static, wai-extra,
|
wai, wai-middleware-static, wai-extra,
|
||||||
transformers, mtl,
|
transformers, mtl,
|
||||||
text, text-format, aeson, bytestring, binary,
|
text, aeson, bytestring, binary,
|
||||||
hashtables, cryptohash, random,
|
hashtables, cryptohash, random,
|
||||||
xdg-basedir, configurator, directory
|
xdg-basedir, configurator, directory
|
||||||
ghc-options: -threaded -O2
|
ghc-options: -threaded -O2
|
||||||
|
@ -10,7 +10,7 @@ import Data.Monoid
|
|||||||
import Control.Monad.IO.Class (liftIO)
|
import Control.Monad.IO.Class (liftIO)
|
||||||
import Data.Aeson hiding (json)
|
import Data.Aeson hiding (json)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text.Format as F
|
import qualified Data.Text.IO as T
|
||||||
|
|
||||||
import Web.Spock.Safe
|
import Web.Spock.Safe
|
||||||
import Network.HTTP.Types.Status
|
import Network.HTTP.Types.Status
|
||||||
@ -27,6 +27,10 @@ reply :: Status -> Text -> ActionT IO ()
|
|||||||
reply code text = setStatus code >> render (message text)
|
reply code text = setStatus code >> render (message text)
|
||||||
|
|
||||||
|
|
||||||
|
logStr :: Text -> ActionT IO ()
|
||||||
|
logStr = liftIO . T.putStrLn
|
||||||
|
|
||||||
|
|
||||||
app :: Url -> UrlTable -> SpockT IO ()
|
app :: Url -> UrlTable -> SpockT IO ()
|
||||||
app url' table = do
|
app url' table = do
|
||||||
static <- liftIO (getDataFileName "static/")
|
static <- liftIO (getDataFileName "static/")
|
||||||
@ -41,7 +45,7 @@ app url' table = do
|
|||||||
case url of
|
case url of
|
||||||
Nothing -> reply status404 "404: does not exist"
|
Nothing -> reply status404 "404: does not exist"
|
||||||
Just url -> do
|
Just url -> do
|
||||||
F.print "Resolved {} -> {} " (name, url)
|
logStr ("Resolved " <> name <> " -> " <> url)
|
||||||
redirect url
|
redirect url
|
||||||
|
|
||||||
post "/" $ do
|
post "/" $ do
|
||||||
@ -50,9 +54,8 @@ app url' table = do
|
|||||||
Nothing -> reply status400 "400: bad request"
|
Nothing -> reply status400 "400: bad request"
|
||||||
Just url -> do
|
Just url -> do
|
||||||
name <- liftIO (insert table url)
|
name <- liftIO (insert table url)
|
||||||
F.print "Registered {} -> {} " (url, name)
|
logStr ("Registered " <> url <> " -> " <> name)
|
||||||
let link = url' <> name
|
render (done $ url' <> name)
|
||||||
render (done link)
|
|
||||||
|
|
||||||
post "api" $ do
|
post "api" $ do
|
||||||
url <- param "url"
|
url <- param "url"
|
||||||
@ -63,7 +66,7 @@ app url' table = do
|
|||||||
, "msg" .= ("missing url field" :: Text ) ]
|
, "msg" .= ("missing url field" :: Text ) ]
|
||||||
Just url -> do
|
Just url -> do
|
||||||
name <- liftIO (insert table url)
|
name <- liftIO (insert table url)
|
||||||
F.print "Registered {} -> {} " (url, name)
|
logStr ("Registered " <> url <> " -> " <> name)
|
||||||
json $ object [ "link" .= (url' <> name)
|
json $ object [ "link" .= (url' <> name)
|
||||||
, "name" .= name
|
, "name" .= name
|
||||||
, "original" .= url ]
|
, "original" .= url ]
|
||||||
|
Loading…
Reference in New Issue
Block a user