#204: Added file upload baseline to app creator
This commit is contained in:
@@ -397,7 +397,7 @@ class AppBase:
|
||||
}
|
||||
|
||||
ret1 = requests.get("%s%s" % (self.url, get_path), headers=headers)
|
||||
print("RET1: %s" % ret1.text)
|
||||
print("RET1 (file get): %s" % ret1.text)
|
||||
if ret1.status_code != 200:
|
||||
returns.append({
|
||||
"filename": "",
|
||||
@@ -408,7 +408,7 @@ class AppBase:
|
||||
|
||||
content_path = "/api/v1/files/%s/content?execution_id=%s" % (item, full_execution["execution_id"])
|
||||
ret2 = requests.get("%s%s" % (self.url, content_path), headers=headers)
|
||||
print("Ret2: %s" % ret2.text)
|
||||
print("RET2 (file get): %s" % ret2.text)
|
||||
if ret2.status_code == 200:
|
||||
tmpdata = ret1.json()
|
||||
returndata = {
|
||||
@@ -418,6 +418,8 @@ class AppBase:
|
||||
}
|
||||
returns.append(returndata)
|
||||
|
||||
print("RET3 (file get done)")
|
||||
|
||||
if len(returns) == 0:
|
||||
return {
|
||||
"success": False,
|
||||
@@ -1687,7 +1689,7 @@ class AppBase:
|
||||
print("[INFO] APP_SDK DONE: Starting NORMAL execution of function")
|
||||
print("[INFO] Running with params (0): %s" % params)
|
||||
newres = await func(**params)
|
||||
print("[INFO] Returned from execution.")
|
||||
print("[INFO] Returned from execution:", newres)
|
||||
if isinstance(newres, tuple):
|
||||
print("[INFO] Handling return as tuple")
|
||||
# Handles files.
|
||||
|
||||
@@ -365,6 +365,16 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet
|
||||
preparedHeaders += "}"
|
||||
}
|
||||
|
||||
fileBalance := ""
|
||||
fileAdder := ``
|
||||
fileGrabber := ``
|
||||
if method == "post" && strings.Contains(functionname, "filescan") {
|
||||
fileGrabber = `filedata = self.get_file("63264006-5958-451a-bff1-1975495fb4d8")`
|
||||
//fileGrabber += "\n print(filedata)"
|
||||
fileAdder = `files = {"file": (filedata["filename"], filedata["data"])}`
|
||||
fileBalance = ", files=files"
|
||||
}
|
||||
|
||||
// Extra param for url if it's changeable
|
||||
// Extra param for authentication scheme(s)
|
||||
// The last weird one is the body.. Tabs & spaces sucks.
|
||||
@@ -375,7 +385,9 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
return requests.%s(url, headers=headers%s%s%s).text
|
||||
%s
|
||||
%s
|
||||
return requests.%s(url, headers=headers%s%s%s%s).text
|
||||
`,
|
||||
functionname,
|
||||
authenticationParameter,
|
||||
@@ -391,17 +403,20 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet
|
||||
authenticationSetup,
|
||||
queryData,
|
||||
bodyFormatter,
|
||||
fileGrabber,
|
||||
fileAdder,
|
||||
method,
|
||||
authenticationAddin,
|
||||
bodyAddin,
|
||||
verifyAddin,
|
||||
fileBalance,
|
||||
)
|
||||
|
||||
//log.Printf("FUNCTION: %s", data)
|
||||
//if strings.Contains(functionname, "search") {
|
||||
// log.Println(data)
|
||||
// log.Printf("Queries: %s", queryString)
|
||||
//}
|
||||
if strings.Contains(functionname, "filescan") {
|
||||
log.Println(data)
|
||||
log.Printf("Queries: %s", queryString)
|
||||
}
|
||||
|
||||
//log.Printf(data)
|
||||
return functionname, data
|
||||
|
||||
@@ -226,6 +226,7 @@ const AppCreator = (props) => {
|
||||
const [errorCode, setErrorCode] = useState("")
|
||||
const [appBuilding, setAppBuilding] = useState(false)
|
||||
const [extraBodyFields, setExtraBodyFields] = useState([])
|
||||
const [fileUploadEnabled, setFileUploadEnabled] = useState(false)
|
||||
|
||||
//const [actions, setActions] = useState([{
|
||||
// "name": "Get workflows",
|
||||
@@ -254,6 +255,7 @@ const AppCreator = (props) => {
|
||||
const [currentActionMethod, setCurrentActionMethod] = useState(actionNonBodyRequest[0])
|
||||
const [currentAction, setCurrentAction] = useState({
|
||||
"name": "",
|
||||
"file_field": "",
|
||||
"description": "",
|
||||
"url": "",
|
||||
"headers": "",
|
||||
@@ -494,6 +496,7 @@ const AppCreator = (props) => {
|
||||
"name": tmpname,
|
||||
"description": methodvalue.description,
|
||||
"url": path,
|
||||
"file_field": "",
|
||||
"method": method.toUpperCase(),
|
||||
"headers": "",
|
||||
"queries": [],
|
||||
@@ -959,6 +962,11 @@ const AppCreator = (props) => {
|
||||
data.paths[item.url][item.method.toLowerCase()].parameters.push(newitem)
|
||||
}
|
||||
|
||||
// https://swagger.io/docs/specification/describing-request-body/file-upload/
|
||||
if (item.file_field !== undefined && item.file_field !== null && item.file_field.length > 0) {
|
||||
console.log("HANDLE FILEFIELD SAVE: ", item.file_field)
|
||||
}
|
||||
|
||||
if (item.headers.length > 0) {
|
||||
const required = false
|
||||
|
||||
@@ -1171,6 +1179,7 @@ const AppCreator = (props) => {
|
||||
"name": "",
|
||||
"description": "",
|
||||
"url": "",
|
||||
"file_field": "",
|
||||
"headers": "",
|
||||
"paths": [],
|
||||
"queries": [],
|
||||
@@ -1609,6 +1618,7 @@ const AppCreator = (props) => {
|
||||
"name": "",
|
||||
"description": "",
|
||||
"url": "",
|
||||
"file_field": "",
|
||||
"headers": "",
|
||||
"paths": [],
|
||||
"queries": [],
|
||||
@@ -1619,6 +1629,7 @@ const AppCreator = (props) => {
|
||||
setCurrentActionMethod(apikeySelection[0])
|
||||
setUrlPathQueries([])
|
||||
setActionsModalOpen(false)
|
||||
setFileUploadEnabled(false)
|
||||
}}
|
||||
>
|
||||
<FormControl style={{backgroundColor: surfaceColor, color: "white",}}>
|
||||
@@ -1806,6 +1817,36 @@ const AppCreator = (props) => {
|
||||
<Button color="primary" style={{marginTop: "5px", marginBottom: "10px", borderRadius: "0px"}} variant="outlined" onClick={() => {
|
||||
addPathQuery()
|
||||
}}>New query</Button>
|
||||
{currentActionMethod === "POST" ?
|
||||
<Button color="primary" variant={fileUploadEnabled ? "contained" : "outlined"} style={{marginLeft: 10, marginTop: "5px", marginBottom: "10px", borderRadius: "0px"}} onClick={() => {
|
||||
setFileUploadEnabled(!fileUploadEnabled)
|
||||
if (fileUploadEnabled && currentAction["file_field"].length > 0) {
|
||||
setActionField("file_field", "")
|
||||
}
|
||||
setUpdate(Math.random())
|
||||
}}>Enable Fileupload</Button>
|
||||
: null}
|
||||
{fileUploadEnabled ?
|
||||
<TextField
|
||||
required
|
||||
style={{backgroundColor: inputColor, display: "inline-block",}}
|
||||
placeholder={"file"}
|
||||
margin="normal"
|
||||
variant="outlined"
|
||||
id="standard-required"
|
||||
defaultValue={currentAction["file_field"]}
|
||||
onChange={e => setActionField("file_field", e.target.value)}
|
||||
helperText={<span style={{color:"white", marginBottom: "2px",}}>The File field to interact with</span>}
|
||||
InputProps={{
|
||||
classes: {
|
||||
notchedOutline: classes.notchedOutline,
|
||||
},
|
||||
style:{
|
||||
color: "white",
|
||||
},
|
||||
}}
|
||||
/>
|
||||
: null}
|
||||
<div/>
|
||||
<b>Headers</b>: static for the action
|
||||
<TextField
|
||||
@@ -1848,6 +1889,7 @@ const AppCreator = (props) => {
|
||||
setActionsModalOpen(false)
|
||||
setUrlPathQueries([])
|
||||
setUrlPath("")
|
||||
setFileUploadEnabled(false)
|
||||
}}>
|
||||
Submit
|
||||
</Button>
|
||||
@@ -1916,6 +1958,7 @@ const AppCreator = (props) => {
|
||||
"name": "",
|
||||
"description": "",
|
||||
"url": "",
|
||||
"file_field": "",
|
||||
"headers": "",
|
||||
"queries": [],
|
||||
"paths": [],
|
||||
|
||||
@@ -807,12 +807,16 @@ const Apps = (props) => {
|
||||
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.addEventListener('load', (e) => {
|
||||
const content = e.target.result;
|
||||
setOpenApiData(content);
|
||||
setIsDropzone(isDropzone);
|
||||
setOpenApiModal(true)
|
||||
})
|
||||
try {
|
||||
reader.addEventListener('load', (e) => {
|
||||
const content = e.target.result;
|
||||
setOpenApiData(content);
|
||||
setIsDropzone(isDropzone);
|
||||
setOpenApiModal(true)
|
||||
})
|
||||
} catch (e) {
|
||||
console.log("Error in dropzone: ", e)
|
||||
}
|
||||
|
||||
reader.readAsText(files[0]);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user