Add json object for environment info for each function, this is mutable from custom code
This commit is contained in:
24
app.py
24
app.py
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
import os
|
||||
from flask import Flask, Response, jsonify, redirect, render_template, request, url_for
|
||||
import jinja_partials
|
||||
@@ -92,12 +93,15 @@ def create_http_function():
|
||||
try:
|
||||
name = request.json.get('name')
|
||||
script_content = request.json.get('script_content')
|
||||
db.create_new_http_function(name, script_content)
|
||||
environment_info = json.dumps(eval(request.json.get('environment_info')))
|
||||
|
||||
db.create_new_http_function(name, script_content, environment_info)
|
||||
|
||||
http_functions = db.get_http_functions()
|
||||
http_functions = create_http_functions_view_model(http_functions)
|
||||
return render_template("dashboard/http_functions.html", http_functions=http_functions)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return render_template("dashboard/http_functions/new.html", name=name, script=script_content)
|
||||
|
||||
@ app.route("/dashboard/http_functions/edit_form", methods=["GET"])
|
||||
@@ -107,19 +111,20 @@ def get_http_function_edit_form():
|
||||
if not http_function:
|
||||
return jsonify({'error': 'Function not found'}), 404
|
||||
script = http_function['script_content']
|
||||
return render_template("dashboard/http_functions/edit.html", name=name, script=script)
|
||||
environment_info = json.dumps(http_function['environment_info'])
|
||||
return render_template("dashboard/http_functions/edit.html", name=name, script=script, environment_info=environment_info)
|
||||
|
||||
@ app.route("/dashboard/http_functions/edit", methods=["POST"])
|
||||
def edit_http_function():
|
||||
try:
|
||||
name = request.json.get('name')
|
||||
script_content = request.json.get('script_content')
|
||||
db.edit_http_function(name, script_content)
|
||||
environment_info = json.dumps(eval(request.json.get('environment_info')))
|
||||
|
||||
http_functions = db.get_http_functions()
|
||||
http_functions = create_http_functions_view_model(http_functions)
|
||||
return render_template("dashboard/http_functions.html", http_functions=http_functions)
|
||||
db.edit_http_function(name, script_content, environment_info)
|
||||
return render_template("dashboard/http_functions/edit.html", name=name, script=script_content, environment_info=environment_info)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return render_template("dashboard/http_functions/edit.html", name=name, script=script_content)
|
||||
|
||||
@ app.route("/dashboard/http_functions/delete", methods=["DELETE"])
|
||||
@@ -174,10 +179,9 @@ def execute_http_function(function):
|
||||
http_function = db.get_http_function(function)
|
||||
if not http_function:
|
||||
return jsonify({'error': 'Function not found'}), 404
|
||||
# TODO: Get code from database based on function name
|
||||
|
||||
code = http_function['script_content']
|
||||
|
||||
print(code)
|
||||
environment = http_function['environment_info']
|
||||
|
||||
request_obj = {
|
||||
'method': request.method,
|
||||
@@ -203,7 +207,7 @@ def execute_http_function(function):
|
||||
request_obj['text'] = request.data.decode('utf-8')
|
||||
|
||||
# Call the Node.js API
|
||||
response = requests.post(API_URL, json={'code': code, 'request': request_obj})
|
||||
response = requests.post(API_URL, json={'code': code, 'request': request_obj, 'environment': environment})
|
||||
response_data = response.json()
|
||||
|
||||
# Map the Node.js response to Flask response
|
||||
|
||||
Reference in New Issue
Block a user