+{-# OPTIONS_GHC -fno-warn-orphans -fno-warn-unused-matches #-}
+
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE TypeOperators #-}
-{-# OPTIONS_GHC -fno-warn-orphans -fno-warn-unused-matches -fno-warn-unused-imports #-}
+{-# LANGUAGE IncoherentInstances #-}
module Gargantext.API.Node.File where
import Control.Lens ((^.))
-import qualified Data.ByteString as BS
-import qualified Data.ByteString.Lazy as BSL
-import qualified Data.MIME.Types as DMT
-import Data.Monoid (mempty)
import Data.Swagger
import Data.Text
-import Data.Text.Encoding
-import qualified Data.Text.IO as TIO
import GHC.Generics (Generic)
-import qualified Network.HTTP.Media as M
-import Network.Wai.Application.Static
import Servant
-import Servant.API.Raw (Raw)
import Servant.Job.Async (JobFunction(..), serveJobsAPI)
-import Servant.Job.Core
-import Servant.Job.Types
-import Servant.Job.Utils (jsonOptions)
-import Servant.Server.Internal
-
-import Gargantext.Prelude
-import qualified Gargantext.Prelude.Utils as GPU
+import qualified Data.ByteString as BS
+import qualified Data.ByteString.Lazy as BSL
+import qualified Data.MIME.Types as DMT
+import qualified Gargantext.Database.GargDB as GargDB
+import qualified Network.HTTP.Media as M
-import Gargantext.Core.Types (TODO)
import Gargantext.API.Admin.Orchestrator.Types (JobLog(..), AsyncJobs)
import Gargantext.API.Admin.Types (HasSettings)
import Gargantext.API.Node.Types
import Gargantext.API.Prelude
+import Gargantext.Core.Types (TODO)
import Gargantext.Database.Action.Flow.Types
import Gargantext.Database.Action.Node (mkNodeWithParent)
import Gargantext.Database.Admin.Types.Hyperdata.File
import Gargantext.Database.Query.Table.Node (getNodeWith)
import Gargantext.Database.Query.Table.Node.UpdateOpaleye (updateHyperdata)
import Gargantext.Database.Schema.Node (node_hyperdata)
+import Gargantext.Prelude
+import Data.Either
data RESPONSE deriving Typeable
:> "download"
:> Get '[RESPONSE] (Headers '[Servant.Header "Content-Type" Text] BSResponse)
+instance MimeUnrender RESPONSE BSResponse where
+ mimeUnrender _ lbs = Right $ BSResponse (BSL.toStrict lbs)
+
fileApi :: UserId -> NodeId -> GargServer FileApi
fileApi uId nId = fileDownload uId nId
newtype Contents = Contents BS.ByteString
-instance GPU.ReadFile Contents where
+instance GargDB.ReadFile Contents where
readFile' fp = do
c <- BS.readFile fp
pure $ Contents c
let (HyperdataFile { _hff_name = name'
, _hff_path = path }) = node ^. node_hyperdata
- Contents c <- GPU.readFile $ unpack path
+ Contents c <- GargDB.readGargFile $ unpack path
let (mMime, _) = DMT.guessType DMT.defaultmtd False $ unpack name'
mime = case mMime of
, _scst_events = Just []
}
- fPath <- GPU.writeFile nwf
+ fPath <- GargDB.writeFile nwf
printDebug "[addWithFile] File saved as: " fPath
nIds <- mkNodeWithParent NodeFile (Just nId) uId fName