#204: Added app creator file upload possibility
This commit is contained in:
+55
-13
@@ -244,7 +244,7 @@ func buildStructure(swagger *openapi3.Swagger, curHash string) (string, error) {
|
|||||||
|
|
||||||
// This function generates the python code that's being used.
|
// This function generates the python code that's being used.
|
||||||
// This is really meta when you program it. Handling parameters is hard here.
|
// This is really meta when you program it. Handling parameters is hard here.
|
||||||
func makePythoncode(swagger *openapi3.Swagger, name, url, method string, parameters, optionalQueries, headers []string) (string, string) {
|
func makePythoncode(swagger *openapi3.Swagger, name, url, method string, parameters, optionalQueries, headers []string, fileField string) (string, string) {
|
||||||
method = strings.ToLower(method)
|
method = strings.ToLower(method)
|
||||||
queryString := ""
|
queryString := ""
|
||||||
queryData := ""
|
queryData := ""
|
||||||
@@ -368,17 +368,19 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet
|
|||||||
fileBalance := ""
|
fileBalance := ""
|
||||||
fileAdder := ``
|
fileAdder := ``
|
||||||
fileGrabber := ``
|
fileGrabber := ``
|
||||||
if method == "post" && strings.Contains(functionname, "filescan") {
|
fileParameter := ``
|
||||||
fileGrabber = `filedata = self.get_file("63264006-5958-451a-bff1-1975495fb4d8")`
|
if method == "post" && len(fileField) > 0 {
|
||||||
|
fileGrabber = `filedata = self.get_file(file_id)`
|
||||||
//fileGrabber += "\n print(filedata)"
|
//fileGrabber += "\n print(filedata)"
|
||||||
fileAdder = `files = {"file": (filedata["filename"], filedata["data"])}`
|
fileAdder = fmt.Sprintf(`files = {"%s": (filedata["filename"], filedata["data"])}`, fileField)
|
||||||
fileBalance = ", files=files"
|
fileBalance = ", files=files"
|
||||||
|
fileParameter = ", file_id"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extra param for url if it's changeable
|
// Extra param for url if it's changeable
|
||||||
// Extra param for authentication scheme(s)
|
// Extra param for authentication scheme(s)
|
||||||
// The last weird one is the body.. Tabs & spaces sucks.
|
// The last weird one is the body.. Tabs & spaces sucks.
|
||||||
data := fmt.Sprintf(` async def %s(self%s%s%s%s%s%s):
|
data := fmt.Sprintf(` async def %s(self%s%s%s%s%s%s%s):
|
||||||
%s
|
%s
|
||||||
url=f"%s%s"
|
url=f"%s%s"
|
||||||
%s
|
%s
|
||||||
@@ -392,6 +394,7 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet
|
|||||||
functionname,
|
functionname,
|
||||||
authenticationParameter,
|
authenticationParameter,
|
||||||
urlParameter,
|
urlParameter,
|
||||||
|
fileParameter,
|
||||||
parameterData,
|
parameterData,
|
||||||
queryString,
|
queryString,
|
||||||
bodyParameter,
|
bodyParameter,
|
||||||
@@ -412,7 +415,7 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet
|
|||||||
fileBalance,
|
fileBalance,
|
||||||
)
|
)
|
||||||
|
|
||||||
if strings.Contains(functionname, "get_list_rulesssss") {
|
if strings.Contains(functionname, "filescan") {
|
||||||
//log.Printf("FUNCTION: %s", data)
|
//log.Printf("FUNCTION: %s", data)
|
||||||
log.Println(data)
|
log.Println(data)
|
||||||
log.Printf("Queries: %s", queryString)
|
log.Printf("Queries: %s", queryString)
|
||||||
@@ -1097,7 +1100,7 @@ func handleConnect(swagger *openapi3.Swagger, api WorkflowApp, extraParameters [
|
|||||||
action.Parameters = append(action.Parameters, optionalParam)
|
action.Parameters = append(action.Parameters, optionalParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "connect", parameters, optionalQueries, headersFound)
|
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "connect", parameters, optionalQueries, headersFound, "")
|
||||||
|
|
||||||
if len(functionname) > 0 {
|
if len(functionname) > 0 {
|
||||||
action.Name = functionname
|
action.Name = functionname
|
||||||
@@ -1232,7 +1235,7 @@ func handleGet(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wor
|
|||||||
action.Parameters = append(action.Parameters, optionalParam)
|
action.Parameters = append(action.Parameters, optionalParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "get", parameters, optionalQueries, headersFound)
|
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "get", parameters, optionalQueries, headersFound, "")
|
||||||
|
|
||||||
if len(functionname) > 0 {
|
if len(functionname) > 0 {
|
||||||
action.Name = functionname
|
action.Name = functionname
|
||||||
@@ -1365,7 +1368,7 @@ func handleHead(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wo
|
|||||||
action.Parameters = append(action.Parameters, optionalParam)
|
action.Parameters = append(action.Parameters, optionalParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "head", parameters, optionalQueries, headersFound)
|
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "head", parameters, optionalQueries, headersFound, "")
|
||||||
|
|
||||||
if len(functionname) > 0 {
|
if len(functionname) > 0 {
|
||||||
action.Name = functionname
|
action.Name = functionname
|
||||||
@@ -1499,7 +1502,7 @@ func handleDelete(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []
|
|||||||
action.Parameters = append(action.Parameters, optionalParam)
|
action.Parameters = append(action.Parameters, optionalParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "delete", parameters, optionalQueries, headersFound)
|
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "delete", parameters, optionalQueries, headersFound, "")
|
||||||
|
|
||||||
if len(functionname) > 0 {
|
if len(functionname) > 0 {
|
||||||
action.Name = functionname
|
action.Name = functionname
|
||||||
@@ -1542,6 +1545,40 @@ func handlePost(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wo
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
fileField := ""
|
||||||
|
if path.Post.RequestBody != nil {
|
||||||
|
//log.Printf("DATA: %#v",
|
||||||
|
value := path.Post.RequestBody.Value
|
||||||
|
//log.Printf("VAL: %#v", value.Content)
|
||||||
|
if val, ok := value.Content["multipart/form-data"]; ok {
|
||||||
|
if val.Schema.Value != nil {
|
||||||
|
if innerval, ok := val.Schema.Value.Properties["fieldname"]; ok {
|
||||||
|
if extensionvalue, ok := innerval.Value.ExtensionProps.Extensions["value"]; ok {
|
||||||
|
fieldname := extensionvalue.(json.RawMessage)
|
||||||
|
newName := string(fmt.Sprintf("%s", string(fieldname)))
|
||||||
|
if newName[0] == 0x22 && newName[len(newName)-1] == 0x22 {
|
||||||
|
parsedName := newName[1 : len(newName)-1]
|
||||||
|
log.Printf("Parse name: %s", parsedName)
|
||||||
|
fileField = parsedName
|
||||||
|
|
||||||
|
curParam := WorkflowAppActionParameter{
|
||||||
|
Name: "file_id",
|
||||||
|
Description: "Files to be uploaded",
|
||||||
|
Multiline: false,
|
||||||
|
Required: true,
|
||||||
|
Schema: SchemaDefinition{
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
action.Parameters = append(action.Parameters, curParam)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
headersFound := []string{}
|
headersFound := []string{}
|
||||||
if len(path.Post.Parameters) > 0 {
|
if len(path.Post.Parameters) > 0 {
|
||||||
for counter, param := range path.Post.Parameters {
|
for counter, param := range path.Post.Parameters {
|
||||||
@@ -1631,12 +1668,17 @@ func handlePost(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wo
|
|||||||
action.Parameters = append(action.Parameters, optionalParam)
|
action.Parameters = append(action.Parameters, optionalParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "post", parameters, optionalQueries, headersFound)
|
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "post", parameters, optionalQueries, headersFound, fileField)
|
||||||
|
|
||||||
if len(functionname) > 0 {
|
if len(functionname) > 0 {
|
||||||
action.Name = functionname
|
action.Name = functionname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//log.Printf("PARAMS: %d", len(action.Parameters))
|
||||||
|
//for _, param := range action.Parameters {
|
||||||
|
// log.Printf("%#v", param)
|
||||||
|
//}
|
||||||
|
|
||||||
return action, curCode
|
return action, curCode
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1764,7 +1806,7 @@ func handlePatch(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []W
|
|||||||
action.Parameters = append(action.Parameters, optionalParam)
|
action.Parameters = append(action.Parameters, optionalParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "patch", parameters, optionalQueries, headersFound)
|
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "patch", parameters, optionalQueries, headersFound, "")
|
||||||
|
|
||||||
if len(functionname) > 0 {
|
if len(functionname) > 0 {
|
||||||
action.Name = functionname
|
action.Name = functionname
|
||||||
@@ -1898,7 +1940,7 @@ func handlePut(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wor
|
|||||||
action.Parameters = append(action.Parameters, optionalParam)
|
action.Parameters = append(action.Parameters, optionalParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "put", parameters, optionalQueries, headersFound)
|
functionname, curCode := makePythoncode(swagger, functionName, baseUrl, "put", parameters, optionalQueries, headersFound, "")
|
||||||
|
|
||||||
if len(functionname) > 0 {
|
if len(functionname) > 0 {
|
||||||
action.Name = functionname
|
action.Name = functionname
|
||||||
|
|||||||
@@ -2718,6 +2718,8 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
|
|||||||
Errors: workflow.Errors,
|
Errors: workflow.Errors,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cacheKey := fmt.Sprintf("workflowapps-sorted")
|
||||||
|
requestCache.Delete(cacheKey)
|
||||||
log.Printf("Saved new version of workflow %s (%s) for org %s", workflow.Name, fileId, workflow.OrgId)
|
log.Printf("Saved new version of workflow %s (%s) for org %s", workflow.Name, fileId, workflow.OrgId)
|
||||||
resp.WriteHeader(200)
|
resp.WriteHeader(200)
|
||||||
newBody, err := json.Marshal(returndata)
|
newBody, err := json.Marshal(returndata)
|
||||||
|
|||||||
@@ -2611,7 +2611,7 @@ const AngularWorkflow = (props) => {
|
|||||||
const allitems = workflow.actions.concat(workflow.triggers)
|
const allitems = workflow.actions.concat(workflow.triggers)
|
||||||
for (var key in allitems) {
|
for (var key in allitems) {
|
||||||
const item = allitems[key]
|
const item = allitems[key]
|
||||||
if (item.app_name === appName) {
|
if (item.app_name === appName && item.label !== undefined && item.label !== null) {
|
||||||
var number = item.label.split("_")
|
var number = item.label.split("_")
|
||||||
if (isNaN(number[-1]) && parseInt(number[number.length-1]) > highest) {
|
if (isNaN(number[-1]) && parseInt(number[number.length-1]) > highest) {
|
||||||
highest = number[number.length-1]
|
highest = number[number.length-1]
|
||||||
@@ -7108,6 +7108,9 @@ const AngularWorkflow = (props) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if (authenticationOption.label === null
|
||||||
|
// defaultValue={}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import DialogActions from '@material-ui/core/DialogActions';
|
|||||||
import TextField from '@material-ui/core/TextField';
|
import TextField from '@material-ui/core/TextField';
|
||||||
import Tooltip from '@material-ui/core/Tooltip';
|
import Tooltip from '@material-ui/core/Tooltip';
|
||||||
import CheckCircleIcon from '@material-ui/icons/CheckCircle';
|
import CheckCircleIcon from '@material-ui/icons/CheckCircle';
|
||||||
|
import AttachFileIcon from '@material-ui/icons/AttachFile';
|
||||||
import Breadcrumbs from '@material-ui/core/Breadcrumbs';
|
import Breadcrumbs from '@material-ui/core/Breadcrumbs';
|
||||||
import AppsIcon from '@material-ui/icons/Apps';
|
import AppsIcon from '@material-ui/icons/Apps';
|
||||||
import CircularProgress from '@material-ui/core/CircularProgress';
|
import CircularProgress from '@material-ui/core/CircularProgress';
|
||||||
@@ -551,7 +552,19 @@ const AppCreator = (props) => {
|
|||||||
//JSON.stringify(tmpobject, null, 2)
|
//JSON.stringify(tmpobject, null, 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("NOT APPLICATION/JSON: ", methodvalue["requestBody"]["content"])
|
|
||||||
|
console.log(methodvalue["requestBody"]["content"])
|
||||||
|
if (methodvalue["requestBody"]["content"]["multipart/form-data"] !== undefined) {
|
||||||
|
if (methodvalue["requestBody"]["content"]["multipart/form-data"]["schema"] !== undefined) {
|
||||||
|
if (methodvalue["requestBody"]["content"]["multipart/form-data"]["schema"]["type"] === "object") {
|
||||||
|
const fieldname = methodvalue["requestBody"]["content"]["multipart/form-data"]["schema"]["properties"]["fieldname"]
|
||||||
|
if (fieldname !== undefined) {
|
||||||
|
console.log("FIELDNAME: ", fieldname)
|
||||||
|
newaction.file_field = fieldname["value"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -820,7 +833,12 @@ const AppCreator = (props) => {
|
|||||||
"summary": item.name,
|
"summary": item.name,
|
||||||
"operationId": item.name.split(" ").join("_"),
|
"operationId": item.name.split(" ").join("_"),
|
||||||
"description": item.description,
|
"description": item.description,
|
||||||
"parameters": []
|
"parameters": [],
|
||||||
|
"requestBody": {
|
||||||
|
"content": {
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log("ACTION: ", item)
|
//console.log("ACTION: ", item)
|
||||||
@@ -966,6 +984,20 @@ const AppCreator = (props) => {
|
|||||||
// https://swagger.io/docs/specification/describing-request-body/file-upload/
|
// https://swagger.io/docs/specification/describing-request-body/file-upload/
|
||||||
if (item.file_field !== undefined && item.file_field !== null && item.file_field.length > 0) {
|
if (item.file_field !== undefined && item.file_field !== null && item.file_field.length > 0) {
|
||||||
console.log("HANDLE FILEFIELD SAVE: ", item.file_field)
|
console.log("HANDLE FILEFIELD SAVE: ", item.file_field)
|
||||||
|
data.paths[item.url][item.method.toLowerCase()]["requestBody"]["content"]["multipart/form-data"] = {
|
||||||
|
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"fieldname": {
|
||||||
|
"type": "string",
|
||||||
|
"value": item.file_field,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(data.paths[item.url][item.method.toLowerCase()]["requestBody"]["content"]["multipart/form-data"])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.headers.length > 0) {
|
if (item.headers.length > 0) {
|
||||||
@@ -1319,6 +1351,7 @@ const AppCreator = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const url = data.url
|
const url = data.url
|
||||||
|
const hasFile = data["file_field"] !== undefined && data["file_field"] !== null && data["file_field"].length > 0
|
||||||
return (
|
return (
|
||||||
<Paper style={actionListStyle}>
|
<Paper style={actionListStyle}>
|
||||||
{error}
|
{error}
|
||||||
@@ -1333,6 +1366,10 @@ const AppCreator = (props) => {
|
|||||||
if (data["body"] !== undefined && data["body"] !== null && data["body"].length > 0) {
|
if (data["body"] !== undefined && data["body"] !== null && data["body"].length > 0) {
|
||||||
findBodyParams(data["body"])
|
findBodyParams(data["body"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasFile) {
|
||||||
|
setFileUploadEnabled(true)
|
||||||
|
}
|
||||||
}}>
|
}}>
|
||||||
<div style={{display: "flex"}}>
|
<div style={{display: "flex"}}>
|
||||||
<Chip
|
<Chip
|
||||||
@@ -1340,7 +1377,8 @@ const AppCreator = (props) => {
|
|||||||
label={data.method}
|
label={data.method}
|
||||||
/>
|
/>
|
||||||
<span style={{fontSize: 16, marginTop: "auto", marginBottom: "auto",}}>
|
<span style={{fontSize: 16, marginTop: "auto", marginBottom: "auto",}}>
|
||||||
{url} - {data.name}
|
{hasFile ? <AttachFileIcon style={{height: 20, width: 20}} /> : null} {url} - {data.name}
|
||||||
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1819,7 +1857,7 @@ const AppCreator = (props) => {
|
|||||||
addPathQuery()
|
addPathQuery()
|
||||||
}}>New query</Button>
|
}}>New query</Button>
|
||||||
{currentActionMethod === "POST" ?
|
{currentActionMethod === "POST" ?
|
||||||
<Button disabled color="primary" variant={fileUploadEnabled ? "contained" : "outlined"} style={{marginLeft: 10, marginTop: "5px", marginBottom: "10px", borderRadius: "0px"}} onClick={() => {
|
<Button color="primary" variant={fileUploadEnabled ? "contained" : "outlined"} style={{marginLeft: 10, marginTop: "5px", marginBottom: "10px", borderRadius: "0px"}} onClick={() => {
|
||||||
setFileUploadEnabled(!fileUploadEnabled)
|
setFileUploadEnabled(!fileUploadEnabled)
|
||||||
if (fileUploadEnabled && currentAction["file_field"].length > 0) {
|
if (fileUploadEnabled && currentAction["file_field"].length > 0) {
|
||||||
setActionField("file_field", "")
|
setActionField("file_field", "")
|
||||||
|
|||||||
Reference in New Issue
Block a user