Commit 8ba2cb0e authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[graph] screenshot and file endpoint fixes

parent 2f539182
...@@ -350,12 +350,12 @@ performAction (UploadFile nodeType fileType mName blob) { session ...@@ -350,12 +350,12 @@ performAction (UploadFile nodeType fileType mName blob) { session
liftEffect $ onTaskAdd task liftEffect $ onTaskAdd task
liftEffect $ log2 "Uploaded, task:" task liftEffect $ log2 "Uploaded, task:" task
performAction (UploadArbitraryFile nodeType mName blob) { session performAction (UploadArbitraryFile mName blob) { session
, tasks: { onTaskAdd } , tasks: { onTaskAdd }
, tree: (NTree (LNode {id}) _) , tree: (NTree (LNode {id}) _)
} = } =
do do
task <- uploadArbitraryFile session nodeType id { blob, mName } task <- uploadArbitraryFile session id { blob, mName }
liftEffect $ onTaskAdd task liftEffect $ onTaskAdd task
liftEffect $ log2 "Uploaded, task:" task liftEffect $ log2 "Uploaded, task:" task
......
...@@ -25,7 +25,7 @@ data Action = AddNode String GT.NodeType ...@@ -25,7 +25,7 @@ data Action = AddNode String GT.NodeType
| UpdateNode UpdateNodeParams | UpdateNode UpdateNodeParams
| DoSearch GT.AsyncTaskWithType | DoSearch GT.AsyncTaskWithType
| UploadFile GT.NodeType FileType (Maybe String) UploadFileBlob | UploadFile GT.NodeType FileType (Maybe String) UploadFileBlob
| UploadArbitraryFile GT.NodeType (Maybe String) UploadFileBlob | UploadArbitraryFile (Maybe String) UploadFileBlob
| DownloadNode | DownloadNode
| RefreshTree | RefreshTree
...@@ -64,7 +64,7 @@ instance showShow :: Show Action where ...@@ -64,7 +64,7 @@ instance showShow :: Show Action where
show (SharePublic _ ) = "SharePublic" show (SharePublic _ ) = "SharePublic"
show (DoSearch _ ) = "SearchQuery" show (DoSearch _ ) = "SearchQuery"
show (UploadFile _ _ _ _) = "UploadFile" show (UploadFile _ _ _ _) = "UploadFile"
show (UploadArbitraryFile _ _ _) = "UploadArbitraryFile" show (UploadArbitraryFile _ _) = "UploadArbitraryFile"
show RefreshTree = "RefreshTree" show RefreshTree = "RefreshTree"
show DownloadNode = "Download" show DownloadNode = "Download"
show (MoveNode _ ) = "MoveNode" show (MoveNode _ ) = "MoveNode"
...@@ -83,7 +83,7 @@ icon (AddContact _) = glyphiconNodeAction Share ...@@ -83,7 +83,7 @@ icon (AddContact _) = glyphiconNodeAction Share
icon (SharePublic _ ) = glyphiconNodeAction (Publish { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }}) icon (SharePublic _ ) = glyphiconNodeAction (Publish { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (DoSearch _) = glyphiconNodeAction SearchBox icon (DoSearch _) = glyphiconNodeAction SearchBox
icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload
icon (UploadArbitraryFile _ _ _ ) = glyphiconNodeAction Upload icon (UploadArbitraryFile _ _ ) = glyphiconNodeAction Upload
icon RefreshTree = glyphiconNodeAction Refresh icon RefreshTree = glyphiconNodeAction Refresh
icon DownloadNode = glyphiconNodeAction Download icon DownloadNode = glyphiconNodeAction Download
icon (MoveNode _ ) = glyphiconNodeAction (Move { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }}) icon (MoveNode _ ) = glyphiconNodeAction (Move { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
...@@ -104,7 +104,7 @@ text (AddContact _ ) = "Add contact !" ...@@ -104,7 +104,7 @@ text (AddContact _ ) = "Add contact !"
text (SharePublic _ ) = "Publish !" text (SharePublic _ ) = "Publish !"
text (DoSearch _ ) = "Launch search !" text (DoSearch _ ) = "Launch search !"
text (UploadFile _ _ _ _) = "Upload File !" text (UploadFile _ _ _ _) = "Upload File !"
text (UploadArbitraryFile _ _ _) = "Upload arbitrary file !" text (UploadArbitraryFile _ _) = "Upload arbitrary file !"
text RefreshTree = "Refresh Tree !" text RefreshTree = "Refresh Tree !"
text DownloadNode = "Download !" text DownloadNode = "Download !"
text (MoveNode _ ) = "Move !" text (MoveNode _ ) = "Move !"
......
...@@ -166,7 +166,7 @@ uploadButtonCpt = R.hooksComponent "G.C.F.T.N.A.U.uploadButton" cpt ...@@ -166,7 +166,7 @@ uploadButtonCpt = R.hooksComponent "G.C.F.T.N.A.U.uploadButton" cpt
void $ launchAff do void $ launchAff do
case fileType of case fileType of
Arbitrary -> Arbitrary ->
dispatch $ UploadArbitraryFile nodeType (Just name) blob dispatch $ UploadArbitraryFile (Just name) blob
_ -> _ ->
dispatch $ UploadFile nodeType fileType (Just name) blob dispatch $ UploadFile nodeType fileType (Just name) blob
liftEffect $ do liftEffect $ do
...@@ -296,32 +296,25 @@ uploadFile session nodeType id fileType {mName, blob: UploadFileBlob blob} = do ...@@ -296,32 +296,25 @@ uploadFile session nodeType id fileType {mName, blob: UploadFileBlob blob} = do
uploadArbitraryFile :: Session uploadArbitraryFile :: Session
-> GT.NodeType
-> ID -> ID
-> {blob :: UploadFileBlob, mName :: Maybe String} -> {blob :: UploadFileBlob, mName :: Maybe String}
-> Aff GT.AsyncTaskWithType -> Aff GT.AsyncTaskWithType
uploadArbitraryFile session nodeType id {mName, blob: UploadFileBlob blob} = do uploadArbitraryFile session id {mName, blob: UploadFileBlob blob} = do
if nodeType == Corpus then
pure unit
else
throwError $ error $ "[uploadArbitraryFile] NodeType " <> (show nodeType) <> " not supported"
contents <- readAsDataURL blob contents <- readAsDataURL blob
uploadArbitraryDataURL session nodeType id mName contents uploadArbitraryDataURL session id mName contents
uploadArbitraryDataURL :: Session uploadArbitraryDataURL :: Session
-> GT.NodeType
-> ID -> ID
-> Maybe String -> Maybe String
-> String -> String
-> Aff GT.AsyncTaskWithType -> Aff GT.AsyncTaskWithType
uploadArbitraryDataURL session nodeType id mName contents' = do uploadArbitraryDataURL session id mName contents' = do
let re = unsafePartial $ fromRight $ DSR.regex "data:.*;base64," DSRF.noFlags let re = unsafePartial $ fromRight $ DSR.regex "data:.*;base64," DSRF.noFlags
contents = DSR.replace re "" contents' contents = DSR.replace re "" contents'
task <- postWwwUrlencoded session p (bodyParams contents) task <- postWwwUrlencoded session p (bodyParams contents)
pure $ GT.AsyncTaskWithType { task, typ: GT.Form } pure $ GT.AsyncTaskWithType { task, typ: GT.Form }
where where
p = GR.NodeAPI nodeType (Just id) $ GT.asyncTaskTypePath GT.UploadFile p = GR.NodeAPI GT.Node (Just id) $ GT.asyncTaskTypePath GT.UploadFile
bodyParams c = [ Tuple "_wfi_b64_data" (Just c) bodyParams c = [ Tuple "_wfi_b64_data" (Just c)
, Tuple "_wfi_name" mName , Tuple "_wfi_name" mName
......
...@@ -18,7 +18,6 @@ import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadArbitraryData ...@@ -18,7 +18,6 @@ import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadArbitraryData
import Gargantext.Hooks.Sigmax as Sigmax import Gargantext.Hooks.Sigmax as Sigmax
import Gargantext.Hooks.Sigmax.Sigma as Sigma import Gargantext.Hooks.Sigmax.Sigma as Sigma
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types as GT
type Props = ( type Props = (
onClick :: forall e. e -> Effect Unit onClick :: forall e. e -> Effect Unit
...@@ -58,6 +57,6 @@ cameraButton session id sigmaRef = simpleButton { ...@@ -58,6 +57,6 @@ cameraButton session id sigmaRef = simpleButton {
screen <- Sigma.takeScreenshot s screen <- Sigma.takeScreenshot s
log2 "[cameraButton] screenshot" screen log2 "[cameraButton] screenshot" screen
launchAff_ $ do launchAff_ $ do
uploadArbitraryDataURL session GT.Graph id (Just "screenshot.png") screen uploadArbitraryDataURL session id (Just "screenshot.png") screen
, text: "Screenshot" , text: "Screenshot"
} }
...@@ -608,7 +608,7 @@ instance decodeJsonAsyncTaskType :: DecodeJson AsyncTaskType where ...@@ -608,7 +608,7 @@ instance decodeJsonAsyncTaskType :: DecodeJson AsyncTaskType where
asyncTaskTypePath :: AsyncTaskType -> String asyncTaskTypePath :: AsyncTaskType -> String
asyncTaskTypePath Form = "add/form/async/" asyncTaskTypePath Form = "add/form/async/"
asyncTaskTypePath UploadFile = "add/file/async/" asyncTaskTypePath UploadFile = "async/file/add/"
asyncTaskTypePath Query = "query/" asyncTaskTypePath Query = "query/"
asyncTaskTypePath GraphT = "async/" asyncTaskTypePath GraphT = "async/"
asyncTaskTypePath AddNode = "async/nobody/" asyncTaskTypePath AddNode = "async/nobody/"
......
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