Commit 0e1adbe6 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[upload] file upload works now

parent 5de2890b
...@@ -26,6 +26,7 @@ import Data.Either ...@@ -26,6 +26,7 @@ import Data.Either
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Data.Swagger import Data.Swagger
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as TIO import qualified Data.Text.IO as TIO
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Servant import Servant
...@@ -37,6 +38,8 @@ import Servant.Job.Utils (jsonOptions) ...@@ -37,6 +38,8 @@ import Servant.Job.Utils (jsonOptions)
import Test.QuickCheck.Arbitrary import Test.QuickCheck.Arbitrary
import Web.FormUrlEncoded (FromForm) import Web.FormUrlEncoded (FromForm)
import Gargantext.Prelude
import Gargantext.API.Admin.Orchestrator.Types (JobLog(..)) import Gargantext.API.Admin.Orchestrator.Types (JobLog(..))
import qualified Gargantext.API.Admin.Orchestrator.Types as T import qualified Gargantext.API.Admin.Orchestrator.Types as T
import Gargantext.API.Admin.Settings (HasSettings) import Gargantext.API.Admin.Settings (HasSettings)
...@@ -45,9 +48,13 @@ import Gargantext.Core (Lang(..){-, allLangs-}) ...@@ -45,9 +48,13 @@ import Gargantext.Core (Lang(..){-, allLangs-})
import Gargantext.Core.Types.Individu (User(..)) import Gargantext.Core.Types.Individu (User(..))
import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger) import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger)
import Gargantext.Database.Action.Flow (FlowCmdM, flowCorpus, getDataText, flowDataText, TermType(..), DataOrigin(..){-, allDataOrigins-}) import Gargantext.Database.Action.Flow (FlowCmdM, flowCorpus, getDataText, flowDataText, TermType(..), DataOrigin(..){-, allDataOrigins-})
import Gargantext.Database.Action.Flow.Utils (getUserId)
import Gargantext.Database.Action.Node (mkNodeWithParent)
import Gargantext.Database.Admin.Types.Hyperdata import Gargantext.Database.Admin.Types.Hyperdata
import Gargantext.Database.Admin.Types.Node (CorpusId, UserId) import Gargantext.Database.Admin.Types.Node (CorpusId, NodeType(..), UserId)
import Gargantext.Prelude import Gargantext.Database.Query.Table.Node (getNodeWith)
import Gargantext.Database.Query.Table.Node.UpdateOpaleye (updateHyperdata)
import Gargantext.Database.Schema.Node (node_hyperdata)
import qualified Gargantext.Prelude.Utils as GPU import qualified Gargantext.Prelude.Utils as GPU
import qualified Gargantext.Text.Corpus.API as API import qualified Gargantext.Text.Corpus.API as API
import qualified Gargantext.Text.Corpus.Parsers as Parser (FileFormat(..), parseFormat) import qualified Gargantext.Text.Corpus.Parsers as Parser (FileFormat(..), parseFormat)
...@@ -347,19 +354,32 @@ addToCorpusWithFile :: (HasSettings env, FlowCmdM env err m) ...@@ -347,19 +354,32 @@ addToCorpusWithFile :: (HasSettings env, FlowCmdM env err m)
-> NewWithFile -> NewWithFile
-> (JobLog -> m ()) -> (JobLog -> m ())
-> m JobLog -> m JobLog
addToCorpusWithFile _user cid nwf@(NewWithFile _d _l _n) logStatus = do addToCorpusWithFile user cid nwf@(NewWithFile _d _l fName) logStatus = do
printDebug "[addToCorpusWithForm] Uploading file to corpus: " cid printDebug "[addToCorpusWithFile] Uploading file to corpus: " cid
logStatus JobLog { _scst_succeeded = Just 0 logStatus JobLog { _scst_succeeded = Just 0
, _scst_failed = Just 0 , _scst_failed = Just 0
, _scst_remaining = Just 1 , _scst_remaining = Just 1
, _scst_events = Just [] , _scst_events = Just []
} }
fp <- GPU.writeFile nwf fPath <- GPU.writeFile nwf
printDebug "File saved as: " fp printDebug "[addToCorpusWithFile] File saved as: " fPath
uId <- getUserId user
nIds <- mkNodeWithParent NodeFile (Just cid) uId fName
_ <- case nIds of
[nId] -> do
node <- getNodeWith nId (Proxy :: Proxy HyperdataFile)
let hl = node ^. node_hyperdata
_ <- updateHyperdata nId $ hl { _hff_name = fName
, _hff_path = T.pack fPath }
printDebug "[addToCorpusWithFile] Created node with id: " nId
_ -> pure ()
printDebug "File upload to corpus finished: " cid printDebug "[addToCorpusWithFile] File upload to corpus finished: " cid
pure $ JobLog { _scst_succeeded = Just 1 pure $ JobLog { _scst_succeeded = Just 1
, _scst_failed = Just 0 , _scst_failed = Just 0
, _scst_remaining = Just 0 , _scst_remaining = Just 0
......
...@@ -24,6 +24,12 @@ import Data.Aeson ...@@ -24,6 +24,12 @@ import Data.Aeson
import Data.Swagger import Data.Swagger
import Data.Text (Text) import Data.Text (Text)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Servant
import Servant.Job.Async
import Test.QuickCheck (elements)
import Test.QuickCheck.Arbitrary
import Web.FormUrlEncoded (FromForm)
import Gargantext.API.Admin.Orchestrator.Types (JobLog(..)) import Gargantext.API.Admin.Orchestrator.Types (JobLog(..))
import Gargantext.API.Node.Corpus.New (AsyncJobs) import Gargantext.API.Node.Corpus.New (AsyncJobs)
import Gargantext.API.Prelude import Gargantext.API.Prelude
...@@ -35,11 +41,6 @@ import Gargantext.Database.Query.Table.Node.Error (HasNodeError(..)) ...@@ -35,11 +41,6 @@ import Gargantext.Database.Query.Table.Node.Error (HasNodeError(..))
import Gargantext.Database.Query.Table.Node.User import Gargantext.Database.Query.Table.Node.User
import Gargantext.Database.Schema.Node import Gargantext.Database.Schema.Node
import Gargantext.Prelude import Gargantext.Prelude
import Servant
import Servant.Job.Async
import Test.QuickCheck (elements)
import Test.QuickCheck.Arbitrary
import Web.FormUrlEncoded (FromForm)
------------------------------------------------------------------------ ------------------------------------------------------------------------
data PostNode = PostNode { pn_name :: Text data PostNode = PostNode { pn_name :: Text
......
...@@ -27,13 +27,14 @@ import Gargantext.Database.Admin.Types.Hyperdata.Prelude ...@@ -27,13 +27,14 @@ import Gargantext.Database.Admin.Types.Hyperdata.Prelude
------------------------------------------------------------------------ ------------------------------------------------------------------------
data HyperdataFile = data HyperdataFile =
HyperdataFile { _hff_name :: !Text HyperdataFile { _hff_name :: !Text
, _hff_path :: !Text
, _hff_mime :: !Text , _hff_mime :: !Text
} }
deriving (Generic) deriving (Generic)
defaultHyperdataFile :: HyperdataFile defaultHyperdataFile :: HyperdataFile
defaultHyperdataFile = HyperdataFile "" "" defaultHyperdataFile = HyperdataFile "" "" ""
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- Instances -- Instances
......
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