Add support to switch between deno and nodejs function executor
This commit is contained in:
@@ -105,8 +105,7 @@ http = Blueprint('http', __name__)
|
||||
@login_required
|
||||
def overview():
|
||||
user_id = current_user.id
|
||||
http_functions = db.execute(
|
||||
'SELECT id, user_id, NAME, script_content, invoked_count, environment_info, is_public, log_request, log_response, version_number FROM http_functions WHERE user_id=%s ORDER by id DESC', [user_id])
|
||||
http_functions = db.get_http_functions_for_user(user_id)
|
||||
http_functions = create_http_functions_view_model(http_functions)
|
||||
if htmx:
|
||||
return render_block(environment, "dashboard/http_functions/overview.html", "page", http_functions=http_functions)
|
||||
@@ -128,12 +127,9 @@ def new():
|
||||
is_public = request.json.get('is_public')
|
||||
log_request = request.json.get('log_request')
|
||||
log_response = request.json.get('log_response')
|
||||
runtime = request.json.get('runtime', 'node')
|
||||
|
||||
db.execute(
|
||||
'INSERT INTO http_functions (user_id, NAME, script_content, environment_info, is_public, log_request, log_response) VALUES (%s, %s, %s, %s, %s, %s, %s)',
|
||||
[user_id, name, script_content, environment_info, is_public, log_request, log_response],
|
||||
commit=True
|
||||
)
|
||||
db.create_new_http_function(user_id, name, script_content, environment_info, is_public, log_request, log_response, runtime)
|
||||
|
||||
return jsonify({
|
||||
"status": "success",
|
||||
@@ -155,12 +151,9 @@ def edit(function_id):
|
||||
is_public = request.json.get('is_public')
|
||||
log_request = request.json.get('log_request')
|
||||
log_response = request.json.get('log_response')
|
||||
runtime = request.json.get('runtime', 'node')
|
||||
|
||||
updated_version = db.execute(
|
||||
'UPDATE http_functions SET NAME=%s, script_content=%s, environment_info=%s, is_public=%s, log_request=%s, log_response=%s WHERE user_id=%s AND id=%s RETURNING version_number',
|
||||
[name, script_content, environment_info, is_public, log_request, log_response, user_id, function_id],
|
||||
commit=True, one=True
|
||||
)
|
||||
updated_version = db.edit_http_function(user_id, function_id, name, script_content, environment_info, is_public, log_request, log_response, runtime)
|
||||
|
||||
return { "status": "success", "message": f'{name} updated' }
|
||||
except Exception as e:
|
||||
@@ -184,9 +177,7 @@ def delete(function_id):
|
||||
@login_required
|
||||
def logs(function_id):
|
||||
user_id = current_user.id
|
||||
http_function = db.execute(
|
||||
'SELECT id, user_id, NAME, script_content, invoked_count, environment_info, is_public, log_request, log_response, version_number, created_at FROM http_functions WHERE user_id=%s AND id=%s',
|
||||
[user_id, function_id], one=True)
|
||||
http_function = db.get_http_function_by_id(user_id, function_id)
|
||||
if not http_function:
|
||||
return jsonify({'error': 'Function not found'}), 404
|
||||
name = http_function['name']
|
||||
@@ -199,9 +190,7 @@ def logs(function_id):
|
||||
@login_required
|
||||
def client(function_id):
|
||||
user_id = current_user.id
|
||||
http_function = db.execute(
|
||||
'SELECT id, user_id, NAME, script_content, invoked_count, environment_info, is_public, log_request, log_response, version_number, created_at FROM http_functions WHERE user_id=%s AND id=%s',
|
||||
[user_id, function_id], one=True)
|
||||
http_function = db.get_http_function_by_id(user_id, function_id)
|
||||
if not http_function:
|
||||
return jsonify({'error': 'Function not found'}), 404
|
||||
|
||||
@@ -265,6 +254,7 @@ def editor(function_id):
|
||||
'log_request': http_function['log_request'],
|
||||
'log_response': http_function['log_response'],
|
||||
'version_number': http_function['version_number'],
|
||||
'runtime': http_function.get('runtime', 'node'),
|
||||
'user_id': user_id,
|
||||
'function_id': function_id,
|
||||
# Add new URLs for navigation
|
||||
|
||||
@@ -152,10 +152,10 @@ timer = Blueprint('timer', __name__)
|
||||
@login_required
|
||||
def overview():
|
||||
timer_functions = db.execute("""
|
||||
SELECT id, name, code, environment, trigger_type,
|
||||
frequency_minutes, run_date, next_run,
|
||||
last_run, enabled, invocation_count
|
||||
FROM timer_functions
|
||||
SELECT id, name, code, environment, trigger_type,
|
||||
frequency_minutes, run_date, next_run,
|
||||
last_run, enabled, invocation_count, runtime
|
||||
FROM timer_functions
|
||||
WHERE user_id = %s
|
||||
ORDER BY id DESC
|
||||
""", [current_user.id])
|
||||
@@ -182,6 +182,7 @@ def new():
|
||||
try:
|
||||
data = request.json
|
||||
trigger_type = data.get('trigger_type')
|
||||
runtime = data.get('runtime', 'node')
|
||||
|
||||
# Validate trigger type
|
||||
if trigger_type not in ('interval', 'date'):
|
||||
@@ -202,9 +203,9 @@ def new():
|
||||
# Insert new timer function
|
||||
db.execute("""
|
||||
INSERT INTO timer_functions
|
||||
(name, code, environment, user_id, trigger_type,
|
||||
frequency_minutes, run_date, next_run, enabled)
|
||||
VALUES (%s, %s, %s::jsonb, %s, %s, %s, %s, %s, %s)
|
||||
(name, code, environment, user_id, trigger_type,
|
||||
frequency_minutes, run_date, next_run, enabled, runtime)
|
||||
VALUES (%s, %s, %s::jsonb, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING id
|
||||
""", [
|
||||
data.get('name'),
|
||||
@@ -215,7 +216,8 @@ def new():
|
||||
frequency_minutes if trigger_type == 'interval' else None,
|
||||
run_date if trigger_type == 'date' else None,
|
||||
next_run,
|
||||
True
|
||||
True,
|
||||
runtime
|
||||
],
|
||||
commit=True)
|
||||
|
||||
@@ -236,10 +238,10 @@ def edit(function_id):
|
||||
if request.method == 'GET':
|
||||
# Fetch the timer function
|
||||
timer_function = db.execute("""
|
||||
SELECT id, name, code, environment, version_number, trigger_type,
|
||||
frequency_minutes, run_date, next_run,
|
||||
last_run, enabled, invocation_count
|
||||
FROM timer_functions
|
||||
SELECT id, name, code, environment, version_number, trigger_type,
|
||||
frequency_minutes, run_date, next_run,
|
||||
last_run, enabled, invocation_count, runtime
|
||||
FROM timer_functions
|
||||
WHERE id = %s AND user_id = %s
|
||||
""", [function_id, current_user.id], one=True)
|
||||
|
||||
@@ -254,7 +256,8 @@ def edit(function_id):
|
||||
|
||||
args = {
|
||||
'function_id': function_id,
|
||||
'timer_function': timer_function
|
||||
'timer_function': timer_function,
|
||||
'runtime': timer_function.get('runtime', 'node')
|
||||
}
|
||||
|
||||
if htmx:
|
||||
@@ -265,6 +268,7 @@ def edit(function_id):
|
||||
try:
|
||||
data = request.json
|
||||
trigger_type = data.get('trigger_type')
|
||||
runtime = data.get('runtime', 'node')
|
||||
|
||||
# Validate trigger type
|
||||
if trigger_type not in ('interval', 'date'):
|
||||
@@ -292,7 +296,8 @@ def edit(function_id):
|
||||
frequency_minutes = %s,
|
||||
run_date = %s,
|
||||
next_run = %s,
|
||||
enabled = %s
|
||||
enabled = %s,
|
||||
runtime = %s
|
||||
WHERE id = %s AND user_id = %s
|
||||
RETURNING id
|
||||
""", [
|
||||
@@ -304,6 +309,7 @@ def edit(function_id):
|
||||
run_date if trigger_type == 'date' else None,
|
||||
next_run,
|
||||
data.get('is_enabled', True), # Default to True if not provided
|
||||
runtime,
|
||||
function_id,
|
||||
current_user.id
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user