diff options
Diffstat (limited to 'src/IRE/Application.hs')
-rw-r--r-- | src/IRE/Application.hs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/IRE/Application.hs b/src/IRE/Application.hs new file mode 100644 index 0000000..530e4a4 --- /dev/null +++ b/src/IRE/Application.hs @@ -0,0 +1,35 @@ +{-# LANGUAGE OverloadedStrings #-} + +module IRE.Application ( + app +) where + +import Control.Monad.Trans (liftIO) +import Network.Wai (Application) +import Network.Wai.Middleware.Static (addBase, hasPrefix, staticPolicy, (>->)) +import Network.Wai.Parse (FileInfo(..)) +import System.FilePath.Posix ((</>)) +import Web.Scotty ( ActionM, ScottyM, file, files, get, + json, middleware, post, scottyApp ) + +import IRE.Application.YOLO (findItems) +import IRE.YOLO (Detector) + +app :: FilePath -> Detector -> IO Application +app rootDir net = scottyApp $ ire rootDir net + +ire :: FilePath -> Detector -> ScottyM () +ire rootDir net = do + middleware $ staticPolicy (hasPrefix "static" >-> addBase rootDir) + get "/" $ file (rootDir </> "webui.html") + + post "/findItems" $ apiFindItems net + + +apiFindItems :: Detector -> ActionM () +apiFindItems net = do + fs <- files + let fc = head [ fileContent fi | (_, fi) <- fs ] + resp <- liftIO $ findItems net fc + json resp + |