import Servant.Job.Async
import Web.FormUrlEncoded (FromForm)
-import Gargantext.API.Admin.Orchestrator.Types (JobLog(..), AsyncJobs, jobLogInit, jobLogSucc, jobLogErr)
+import Gargantext.API.Admin.Orchestrator.Types (JobLog(..), AsyncJobs)
+import Gargantext.API.Job (jobLogInit, jobLogSuccess, jobLogFail)
import Gargantext.API.Node.Corpus.New (addToCorpusWithForm)
-import Gargantext.API.Node.Corpus.New.File (FileType(..))
+import Gargantext.API.Node.Corpus.New.Types (FileFormat(..), FileType(..))
import Gargantext.API.Node.Types (NewWithForm(..))
import Gargantext.API.Prelude
import Gargantext.Core.Types.Individu (User(..))
import Gargantext.Database.Action.Flow.Types
import Gargantext.Database.Admin.Types.Hyperdata.Frame
import Gargantext.Database.Admin.Types.Node
+import Gargantext.Database.Prelude (HasConfig)
import Gargantext.Database.Query.Table.Node (getClosestParentIdByType, getNodeWith)
import Gargantext.Database.Schema.Node (node_hyperdata)
import Gargantext.Prelude
instance ToJSON FrameCalcUpload
instance ToSchema FrameCalcUpload
-type FrameCalcUploadAPI = Summary " FrameCalc upload"
- :> "add"
- :> "framecalc"
- :> "async"
- :> AsyncJobs JobLog '[JSON] FrameCalcUpload JobLog
+type API = Summary " FrameCalc upload"
+ :> "add"
+ :> "framecalc"
+ :> "async"
+ :> AsyncJobs JobLog '[JSON] FrameCalcUpload JobLog
-frameCalcUploadAPI :: UserId -> NodeId -> GargServer FrameCalcUploadAPI
-frameCalcUploadAPI uId nId =
+api :: UserId -> NodeId -> GargServer API
+api uId nId =
serveJobsAPI $
JobFunction (\p logs ->
frameCalcUploadAsync uId nId p (liftBase . logs) (jobLogInit 5)
)
-frameCalcUploadAsync :: FlowCmdM env err m
+frameCalcUploadAsync :: (HasConfig env, FlowCmdM env err m)
=> UserId
-> NodeId
-> FrameCalcUpload
httpLbs req manager
let body = T.pack $ BSU8.toString $ BSL.toStrict $ responseBody res
+ -- printDebug "body" body
mCId <- getClosestParentIdByType nId NodeCorpus
-- printDebug "[frameCalcUploadAsync] mCId" mCId
jobLog2 <- case mCId of
- Nothing -> pure $ jobLogErr jobLog
+ Nothing -> pure $ jobLogFail jobLog
Just cId ->
- addToCorpusWithForm (RootId (NodeId uId)) cId (NewWithForm CSV body Nothing "calc-upload.csv") logStatus jobLog
+ addToCorpusWithForm (RootId (NodeId uId)) cId (NewWithForm CSV Plain body Nothing "calc-upload.csv") logStatus jobLog
- pure $ jobLogSucc jobLog2
+ pure $ jobLogSuccess jobLog2