]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Upload.hs
Missing file
[gargantext.git] / src / Gargantext / API / Upload.hs
1 {-|
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
8 Portability : POSIX
9
10 -}
11
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
13
14 {-# LANGUAGE DataKinds #-}
15 {-# LANGUAGE DeriveGeneric #-}
16 {-# LANGUAGE FlexibleContexts #-}
17 {-# LANGUAGE NoImplicitPrelude #-}
18 {-# LANGUAGE OverloadedStrings #-}
19 {-# LANGUAGE RankNTypes #-}
20 {-# LANGUAGE TemplateHaskell #-}
21 {-# LANGUAGE TypeOperators #-}
22
23 module Gargantext.API.Upload
24 where
25
26
27 import Gargantext.Prelude
28 import Data.Text (Text)
29 import Servant
30 import Servant.Multipart
31 import qualified Data.ByteString.Lazy as LBS
32 import Control.Monad
33 import Control.Monad.IO.Class
34 import Gargantext.API.Types
35 import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
36 import Data.Swagger
37
38 -- | Upload files
39 -- TODO Is it possible to adapt the function according to iValue input ?
40 --type API = MultipartForm Mem (MultipartData Mem) :> Post '[JSON] Integer
41
42 instance Generic Mem
43
44 instance ToSchema Mem
45 instance Arbitrary Mem
46
47 instance ToSchema (MultipartData Mem)
48 instance Arbitrary ( MultipartData Mem)
49
50 instance ToSchema (MultipartForm Mem (MultipartData Mem))
51 instance Arbitrary (MultipartForm Mem (MultipartData Mem))
52
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
59 liftIO $ do
60 putStrLn ("Inputs:" :: Text)
61 forM_ (inputs multipartData) $ \input ->
62 putStrLn $ (" " :: Text) <> (iName input)
63 <> (" -> " :: Text) <> (iValue input)
64
65 forM_ (files multipartData) $ \file -> do
66 let content = fdPayload file
67 putStrLn $ ("Content of " :: Text) <> (fdFileName file)
68 LBS.putStr content
69 return 0
70 -------------------------------------------------------------------------------
71