Add dashboard, and flask endpoint that executes a script and returns the result (currently a hardcoded script)
This commit is contained in:
45
app.py
45
app.py
@@ -60,6 +60,10 @@ def index():
|
||||
def client():
|
||||
return render_template("client.html")
|
||||
|
||||
@ app.route("/dashboard", methods=["GET"])
|
||||
def dashboard():
|
||||
return render_template("dashboard.html")
|
||||
|
||||
|
||||
@app.route('/execute', methods=['POST'])
|
||||
def execute_code():
|
||||
@@ -89,6 +93,47 @@ def execute_code():
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
@app.route('/f/<function>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'])
|
||||
def execute_http_function(function):
|
||||
try:
|
||||
# TODO: Get code from database based on function name
|
||||
code = DEFAULT_SCRIPT
|
||||
|
||||
request_obj = {
|
||||
'method': request.method,
|
||||
'headers': dict(request.headers),
|
||||
'url': request.url,
|
||||
# Add other request properties as needed
|
||||
}
|
||||
|
||||
# Add JSON data if it exists
|
||||
if request.is_json:
|
||||
request_obj['json'] = request.get_json()
|
||||
|
||||
# Add form data if it exists
|
||||
if request.form:
|
||||
request_obj['form'] = request.form.to_dict()
|
||||
|
||||
# Add query parameters if they exist
|
||||
if request.args:
|
||||
request_obj['query'] = request.args.to_dict()
|
||||
|
||||
# Add plain text data if it exists
|
||||
if request.data and not request.is_json:
|
||||
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_data = response.json()
|
||||
|
||||
# Map the Node.js response to Flask response
|
||||
flask_response = map_isolator_response_to_flask_response(response_data)
|
||||
return flask_response
|
||||
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
152
templates/dashboard.html
Normal file
152
templates/dashboard.html
Normal file
@@ -0,0 +1,152 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="grid min-h-screen w-full lg:grid-cols-[280px_1fr]" data-id="1">
|
||||
<div class="hidden border-r bg-gray-100/40 lg:block dark:bg-gray-800/40" data-id="2">
|
||||
<div class="flex h-full max-h-screen flex-col gap-2" data-id="3">
|
||||
<div class="flex h-[60px] items-center border-b px-6" data-id="4"><a
|
||||
class="flex items-center gap-2 font-semibold" data-id="5" href="#"><svg
|
||||
xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
||||
class="h-6 w-6" data-id="6">
|
||||
<path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"></path>
|
||||
</svg><span class="" data-id="7">Function Manager</span></a><button
|
||||
class="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground ml-auto h-8 w-8"
|
||||
data-id="8"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||||
stroke-linejoin="round" class="h-4 w-4" data-id="9">
|
||||
<path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"></path>
|
||||
<path d="M10.3 21a1.94 1.94 0 0 0 3.4 0"></path>
|
||||
</svg><span class="sr-only" data-id="10">Toggle notifications</span></button></div>
|
||||
<div class="flex-1 overflow-auto py-2" data-id="11">
|
||||
<nav class="grid items-start px-4 text-sm font-medium" data-id="12"><a
|
||||
class="flex items-center gap-3 rounded-lg px-3 py-2 text-gray-500 transition-all hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-50"
|
||||
data-id="13" href="#"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
|
||||
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4" data-id="14">
|
||||
<path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path>
|
||||
<polyline points="9 22 9 12 15 12 15 22"></polyline>
|
||||
</svg>
|
||||
Home
|
||||
</a><a
|
||||
class="flex items-center gap-3 rounded-lg bg-gray-100 px-3 py-2 text-gray-900 transition-all hover:text-gray-900 dark:bg-gray-800 dark:text-gray-50 dark:hover:text-gray-50"
|
||||
data-id="15" href="#"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
|
||||
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4" data-id="16">
|
||||
<path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"></path>
|
||||
</svg>
|
||||
HTTP
|
||||
</a><a
|
||||
class="flex items-center gap-3 rounded-lg px-3 py-2 text-gray-500 transition-all hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-50"
|
||||
data-id="17" href="#"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
|
||||
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4" data-id="18">
|
||||
<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"></path>
|
||||
<circle cx="9" cy="7" r="4"></circle>
|
||||
<path d="M22 21v-2a4 4 0 0 0-3-3.87"></path>
|
||||
<path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
|
||||
</svg>
|
||||
Timer
|
||||
</a><a
|
||||
class="flex items-center gap-3 rounded-lg px-3 py-2 text-gray-500 transition-all hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-50"
|
||||
data-id="19" href="#"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
|
||||
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4" data-id="20">
|
||||
<path d="M3 3v18h18"></path>
|
||||
<path d="m19 9-5 5-4-4-3 3"></path>
|
||||
</svg>
|
||||
Analytics
|
||||
</a></nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col" data-id="28">
|
||||
<header class="flex h-14 lg:h-[60px] items-center gap-4 border-b bg-gray-100/40 px-6 dark:bg-gray-800/40"
|
||||
data-id="29"><a class="lg:hidden" data-id="30" href="#"><svg xmlns="http://www.w3.org/2000/svg" width="24"
|
||||
height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round" class="h-6 w-6" data-id="31">
|
||||
<path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"></path>
|
||||
</svg><span class="sr-only" data-id="32">Home</span></a>
|
||||
<div class="w-full flex-1" data-id="33">
|
||||
<form data-id="34">
|
||||
<div class="relative" data-id="35"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
|
||||
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round"
|
||||
class="absolute left-2.5 top-2.5 h-4 w-4 text-gray-500 dark:text-gray-400" data-id="36">
|
||||
<circle cx="11" cy="11" r="8"></circle>
|
||||
<path d="m21 21-4.3-4.3"></path>
|
||||
</svg><input
|
||||
class="flex h-10 rounded-md border border-input px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 w-full bg-white shadow-none appearance-none pl-8 md:w-2/3 lg:w-1/3 dark:bg-gray-950"
|
||||
placeholder="Search functions..." data-id="37" type="search"></div>
|
||||
</form>
|
||||
</div><button
|
||||
class="inline-flex items-center justify-center text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 hover:bg-accent hover:text-accent-foreground rounded-full border border-gray-200 w-8 h-8 dark:border-gray-800"
|
||||
data-id="40" type="button" id="radix-:r1u:" aria-haspopup="menu" aria-expanded="false"
|
||||
data-state="closed"><img src="/placeholder.svg" width="32" height="32" class="rounded-full" alt="Avatar"
|
||||
data-id="41" style="aspect-ratio: 32 / 32; object-fit: cover;"><span class="sr-only"
|
||||
data-id="42">Toggle user menu</span></button>
|
||||
</header>
|
||||
<main class="flex flex-1 flex-col gap-4 p-4 md:gap-8 md:p-6" data-id="50">
|
||||
<div class="flex items-center" data-id="51">
|
||||
<h1 class="font-semibold text-lg md:text-2xl" data-id="52">HTTP functions</h1><button
|
||||
class="inline-flex items-center justify-center text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-9 rounded-md px-3 ml-auto"
|
||||
data-id="53">
|
||||
Add Function
|
||||
</button>
|
||||
</div>
|
||||
<div class="border shadow-sm rounded-lg" data-id="54">
|
||||
<div class="relative w-full overflow-auto">
|
||||
<table class="w-full caption-bottom text-sm" data-id="55">
|
||||
<thead class="[&_tr]:border-b" data-id="56">
|
||||
<tr class="border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted"
|
||||
data-id="57">
|
||||
<th class="h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 max-w-[150px]"
|
||||
data-id="59">Name</th>
|
||||
<th class="h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 hidden md:table-cell"
|
||||
data-id="60">URL</th>
|
||||
<th class="h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 hidden md:table-cell"
|
||||
data-id="61">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="[&_tr:last-child]:border-0" data-id="62">
|
||||
<tr class="border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted"
|
||||
data-id="63">
|
||||
<td class="p-4 align-middle [&:has([role=checkbox])]:pr-0 font-medium cursor-pointer"
|
||||
data-id="66">HelloWorld</td>
|
||||
<td class="p-4 align-middle [&:has([role=checkbox])]:pr-0 hidden md:table-cell"
|
||||
data-id="67">
|
||||
<a
|
||||
href="https://function.peterstockings.com/f/helloworld">https://function.peterstockings.com/f/helloworld</a>
|
||||
<button
|
||||
class="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 hover:bg-accent hover:text-accent-foreground px-4 text-gray-600 dark:text-gray-400"
|
||||
data-id="24"><span class="sr-only" data-id="25">Add Link</span><svg
|
||||
xmlns="http://www.w3.org/2000/svg" width="24" height="24"
|
||||
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||||
stroke-linecap="round" stroke-linejoin="round" class="w-4 h-4" data-id="26"
|
||||
data-darkreader-inline-stroke=""
|
||||
style="--darkreader-inline-stroke: currentColor;">
|
||||
<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71">
|
||||
</path>
|
||||
<path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71">
|
||||
</path>
|
||||
</svg></button>
|
||||
</td>
|
||||
<td class="p-4 align-middle [&:has([role=checkbox])]:pr-0 hidden md:table-cell"
|
||||
data-id="68"><button
|
||||
class="inline-flex items-center justify-center text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-9 rounded-md px-3 mr-2"
|
||||
data-id="69">Edit</button><button
|
||||
class="inline-flex items-center justify-center text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-9 rounded-md px-3"
|
||||
data-id="70">Delete</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user