Fetch http_functions from database
This commit is contained in:
18
app.py
18
app.py
@@ -4,11 +4,14 @@ import jinja_partials
|
||||
from jinja2_fragments import render_block
|
||||
from flask_htmx import HTMX
|
||||
import requests
|
||||
from db import DataBase
|
||||
from services import create_http_functions_view_model
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_pyfile('config.py')
|
||||
jinja_partials.register_extensions(app)
|
||||
htmx = HTMX(app)
|
||||
db = DataBase(app)
|
||||
|
||||
API_URL = 'https://isolator.peterstockings.com/execute'
|
||||
|
||||
@@ -62,11 +65,15 @@ def client():
|
||||
|
||||
@ app.route("/dashboard", methods=["GET"])
|
||||
def dashboard():
|
||||
return render_template("dashboard.html")
|
||||
http_functions = db.get_http_functions()
|
||||
http_functions = create_http_functions_view_model(http_functions)
|
||||
return render_template("dashboard.html", http_functions=http_functions)
|
||||
|
||||
@ app.route("/dashboard/http_functions", methods=["GET"])
|
||||
def dashboard_http_functions():
|
||||
return render_template("dashboard/http_functions.html")
|
||||
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)
|
||||
|
||||
@ app.route("/dashboard/timer_functions", methods=["GET"])
|
||||
def dashboard_timer_functions():
|
||||
@@ -105,8 +112,13 @@ def execute_code():
|
||||
@app.route('/f/<function>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'])
|
||||
def execute_http_function(function):
|
||||
try:
|
||||
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 = DEFAULT_SCRIPT
|
||||
code = http_function['script_content']
|
||||
|
||||
print(code)
|
||||
|
||||
request_obj = {
|
||||
'method': request.method,
|
||||
|
||||
Reference in New Issue
Block a user