2 Module : Gargantext.API.Upload
3 Description : Server API
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
14 {-# LANGUAGE DataKinds #-}
15 {-# LANGUAGE DeriveGeneric #-}
16 {-# LANGUAGE FlexibleContexts #-}
17 {-# LANGUAGE NoImplicitPrelude #-}
18 {-# LANGUAGE OverloadedStrings #-}
19 {-# LANGUAGE RankNTypes #-}
20 {-# LANGUAGE TemplateHaskell #-}
21 {-# LANGUAGE TypeOperators #-}
23 module Gargantext.API.Upload
27 import Gargantext.Prelude
28 import Data.Text (Text)
30 import Servant.Multipart
31 import qualified Data.ByteString.Lazy as LBS
33 import Control.Monad.IO.Class
34 import Gargantext.API.Types
35 import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
39 -- TODO Is it possible to adapt the function according to iValue input ?
40 --type API = MultipartForm Mem (MultipartData Mem) :> Post '[JSON] Integer
45 instance Arbitrary Mem
47 instance ToSchema (MultipartData Mem)
48 instance Arbitrary ( MultipartData Mem)
50 instance ToSchema (MultipartForm Mem (MultipartData Mem))
51 instance Arbitrary (MultipartForm Mem (MultipartData Mem))
53 type ApiUpload = MultipartForm Mem (MultipartData Mem) :> Post '[JSON] Integer
54 -- MultipartData consists in textual inputs,
55 -- accessible through its "inputs" field, as well
56 -- as files, accessible through its "files" field.
57 upload :: GargServer ApiUpload
58 upload multipartData = do
60 putStrLn ("Inputs:" :: Text)
61 forM_ (inputs multipartData) $ \input ->
62 putStrLn $ (" " :: Text) <> (iName input)
63 <> (" -> " :: Text) <> (iValue input)
65 forM_ (files multipartData) $ \file -> do
66 let content = fdPayload file
67 putStrLn $ ("Content of " :: Text) <> (fdFileName file)
70 -------------------------------------------------------------------------------