Commit efb4c8a0 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[upload] implement zip file upload

parent 41ecf1e2
...@@ -123,6 +123,7 @@ uploadFileViewCpt = here.component "uploadFileView" cpt ...@@ -123,6 +123,7 @@ uploadFileViewCpt = here.component "uploadFileView" cpt
, WOS , WOS
, PresseRIS , PresseRIS
, Arbitrary , Arbitrary
, ZIP
] CSV setFileType' show ] CSV setFileType' show
] ]
] ]
...@@ -334,31 +335,28 @@ uploadFile session NodeList id JSON { mName, contents } = do ...@@ -334,31 +335,28 @@ uploadFile session NodeList id JSON { mName, contents } = do
task <- post session url body task <- post session url body
pure $ GT.AsyncTaskWithType { task, typ: GT.Form } pure $ GT.AsyncTaskWithType { task, typ: GT.Form }
-} -}
uploadFile { contents, fileType: CSV, id, nodeType: NodeList, mName, session } = do
let url = GR.NodeAPI NodeList (Just id) $ GT.asyncTaskTypePath GT.ListCSVUpload
let body = [ Tuple "_wtf_data" (Just contents)
, Tuple "_wtf_filetype" (Just $ show NodeList)
, Tuple "_wtf_name" mName ]
eTask <- postWwwUrlencoded session url body
pure $ (\task -> GT.AsyncTaskWithType { task, typ: GT.ListCSVUpload }) <$> eTask
uploadFile { contents, fileType, id, nodeType, mName, session } = do uploadFile { contents, fileType, id, nodeType, mName, session } = do
-- contents <- readAsText blob -- contents <- readAsText blob
eTask :: Either RESTError GT.AsyncTask <- postWwwUrlencoded session p bodyParams eTask :: Either RESTError GT.AsyncTask <- postWwwUrlencoded session p body
pure $ (\task -> GT.AsyncTaskWithType { task, typ }) <$> eTask pure $ (\task -> GT.AsyncTaskWithType { task, typ }) <$> eTask
--postMultipartFormData session p fileContents --postMultipartFormData session p fileContents
where where
Tuple typ p = case nodeType of
Corpus -> Tuple GT.CorpusFormUpload (GR.NodeAPI nodeType (Just id) $ GT.asyncTaskTypePath GT.CorpusFormUpload)
Annuaire -> Tuple GT.UploadFile (GR.NodeAPI nodeType (Just id) "annuaire")
NodeList -> case fileType of
JSON -> Tuple GT.ListUpload (GR.NodeAPI nodeType (Just id) $ GT.asyncTaskTypePath GT.ListUpload)
_ -> Tuple GT.UploadFile (GR.NodeAPI nodeType (Just id) "")
_ -> Tuple GT.UploadFile (GR.NodeAPI nodeType (Just id) "")
bodyParams = [ Tuple "_wf_data" (Just contents) bodyParams = [ Tuple "_wf_data" (Just contents)
, Tuple "_wf_filetype" (Just $ show fileType) , Tuple "_wf_filetype" (Just $ show fileType)
, Tuple "_wf_name" mName , Tuple "_wf_name" mName
] ]
csvBodyParams = [ Tuple "_wtf_data" (Just contents)
, Tuple "_wtf_filetype" (Just $ show NodeList)
, Tuple "_wtf_name" mName ]
(typ /\ p /\ body) = case nodeType of
Corpus -> GT.CorpusFormUpload /\ (GR.NodeAPI nodeType (Just id) $ GT.asyncTaskTypePath GT.CorpusFormUpload) /\ bodyParams
Annuaire -> GT.UploadFile /\ (GR.NodeAPI nodeType (Just id) "annuaire") /\ bodyParams
NodeList -> case fileType of
JSON -> GT.ListUpload /\ (GR.NodeAPI nodeType (Just id) $ GT.asyncTaskTypePath GT.ListUpload) /\ bodyParams
CSV -> GT.ListCSVUpload /\ (GR.NodeAPI NodeList (Just id) $ GT.asyncTaskTypePath GT.ListCSVUpload) /\ csvBodyParams
_ -> GT.UploadFile /\ (GR.NodeAPI nodeType (Just id) "") /\ bodyParams
_ -> GT.UploadFile /\ (GR.NodeAPI nodeType (Just id) "") /\ bodyParams
uploadArbitraryFile :: Session uploadArbitraryFile :: Session
......
...@@ -11,13 +11,11 @@ import Web.File.FileReader.Aff (readAsText) ...@@ -11,13 +11,11 @@ import Web.File.FileReader.Aff (readAsText)
import Gargantext.Prelude import Gargantext.Prelude
data FileType = CSV | CSV_HAL | WOS | PresseRIS | Arbitrary | JSON data FileType = CSV | CSV_HAL | WOS | PresseRIS | Arbitrary | JSON | ZIP
derive instance Generic FileType _ derive instance Generic FileType _
instance Eq FileType where instance Eq FileType where eq = genericEq
eq = genericEq instance Show FileType where show = genericShow
instance Show FileType where
show = genericShow
instance Read FileType where instance Read FileType where
read :: String -> Maybe FileType read :: String -> Maybe FileType
read "Arbitrary" = Just Arbitrary read "Arbitrary" = Just Arbitrary
...@@ -26,6 +24,7 @@ instance Read FileType where ...@@ -26,6 +24,7 @@ instance Read FileType where
read "PresseRIS" = Just PresseRIS read "PresseRIS" = Just PresseRIS
read "WOS" = Just WOS read "WOS" = Just WOS
read "JSON" = Just JSON read "JSON" = Just JSON
read "ZIP" = Just ZIP
read _ = Nothing read _ = Nothing
......
...@@ -659,6 +659,7 @@ data AsyncTaskType = AddNode ...@@ -659,6 +659,7 @@ data AsyncTaskType = AddNode
| GraphRecompute | GraphRecompute
| ListUpload | ListUpload
| ListCSVUpload -- legacy v3 CSV upload for lists | ListCSVUpload -- legacy v3 CSV upload for lists
| ListZIPUpload
| Query | Query
| UpdateNgramsCharts | UpdateNgramsCharts
| UpdateNode | UpdateNode
...@@ -679,6 +680,7 @@ asyncTaskTypePath CorpusFormUpload = "add/form/async/" ...@@ -679,6 +680,7 @@ asyncTaskTypePath CorpusFormUpload = "add/form/async/"
asyncTaskTypePath GraphRecompute = "async/recompute/" asyncTaskTypePath GraphRecompute = "async/recompute/"
asyncTaskTypePath ListUpload = "add/form/async/" asyncTaskTypePath ListUpload = "add/form/async/"
asyncTaskTypePath ListCSVUpload = "csv/add/form/async/" asyncTaskTypePath ListCSVUpload = "csv/add/form/async/"
asyncTaskTypePath ListZIPUpload = "zip/add/form/async/"
asyncTaskTypePath Query = "query/" asyncTaskTypePath Query = "query/"
asyncTaskTypePath UpdateNgramsCharts = "ngrams/async/charts/update/" asyncTaskTypePath UpdateNgramsCharts = "ngrams/async/charts/update/"
asyncTaskTypePath UpdateNode = "update/" asyncTaskTypePath UpdateNode = "update/"
......
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