blob: bd8c7961c0c121ecf924f60c6ea8d526c4871277 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
{-# 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
|