Commit cf5f0c0b authored by Alexandre Delanoë's avatar Alexandre Delanoë

[API] upload

parent 7ad8c683
Pipeline #687 canceled with stage
......@@ -285,6 +285,7 @@ type GargPrivateAPI' =
:<|> New.AddWithQuery
:<|> New.AddWithFile
:<|> New.AddWithForm
-- :<|> "scraper" :> WithCallbacks ScraperAPI
-- :<|> "new" :> New.Api
......@@ -366,6 +367,7 @@ serverPrivateGargAPI' (AuthenticatedUser (NodeId uid))
-- TODO access
:<|> addWithQuery
:<|> addWithFile
:<|> addWithForm
-- :<|> addToCorpus
-- :<|> New.api uid -- TODO-SECURITY
-- :<|> New.info uid -- TODO-SECURITY
......@@ -380,6 +382,12 @@ addWithFile cid i f =
serveJobsAPI $
JobFunction (\_i log -> New.addToCorpusWithFile cid i f (liftIO . log))
addWithForm :: GargServer New.AddWithForm
addWithForm cid =
serveJobsAPI $
JobFunction (\i log -> New.addToCorpusWithForm cid i (liftIO . log))
serverStatic :: Server (Get '[HTML] Html)
serverStatic = $(do
let path = "purescript-gargantext/dist/index.html"
......
......@@ -153,6 +153,19 @@ instance FromJSON WithQuery where
instance ToSchema WithQuery
data WithForm = WithForm
{ _wf_filetype :: !FileType
, _wf_data :: !Text
} deriving Generic
makeLenses ''WithForm
instance FromJSON WithForm where
parseJSON = genericParseJSON $ jsonOptions "_wf_"
instance ToSchema WithForm
------------------------------------------------------------------------
type
AddAPI withInput = AsyncJobsAPI ScraperStatus withInput ScraperStatus
......@@ -176,6 +189,15 @@ type AddWithFile = Summary "Add to corpus endpoint"
:> "async"
:> AddAPI ()
type AddWithForm = Summary "Add to corpus endpoint"
:> "corpus"
:> Capture "corpus_id" CorpusId
:> "add"
:> "form"
:> "async"
:> AddAPI WithForm
------------------------------------------------------------------------
-- TODO WithQuery also has a corpus id
addToCorpusJobFunction :: FlowCmdM env err m
......@@ -197,6 +219,7 @@ addToCorpusJobFunction _cid _input logStatus = do
, _scst_events = Just []
}
addToCorpusWithFile :: FlowCmdM env err m
=> CorpusId
-> MultipartData Mem
......@@ -217,3 +240,22 @@ addToCorpusWithFile cid input filetype logStatus = do
, _scst_events = Just []
}
addToCorpusWithForm :: FlowCmdM env err m
=> CorpusId
-> WithForm
-> (ScraperStatus -> m ())
-> m ScraperStatus
addToCorpusWithForm cid (WithForm ft d) logStatus = do
logStatus ScraperStatus { _scst_succeeded = Just 10
, _scst_failed = Just 2
, _scst_remaining = Just 138
, _scst_events = Just []
}
_h <- putStrLn $ show ft
pure ScraperStatus { _scst_succeeded = Just 137
, _scst_failed = Just 13
, _scst_remaining = Just 0
, _scst_events = Just []
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment