diff --git a/webserver/restapi.py b/webserver/restapi.py index acecf13..a6b0f85 100644 --- a/webserver/restapi.py +++ b/webserver/restapi.py @@ -142,6 +142,10 @@ def list_users(): # For now, we will just check if the user is an admin # if not is_admin(): # return jsonify({"msg": "Admin privileges required"}), 403 + + # TODO just returns if there is already users in the database if + # not logged in as admin + # if verify_jwt_in_request(optional=True): try: users = User.query.all() except Exception as e: diff --git a/webserver/webserver.py b/webserver/webserver.py index 4708fcc..6acd669 100644 --- a/webserver/webserver.py +++ b/webserver/webserver.py @@ -59,17 +59,18 @@ def restapi_callback_get(argument: str, data: dict) -> dict: elif argument == "compilation-status": status = openplc_runtime.compilation_status_str - if status == "": - return {"compilation-status": "No compilation in progress"} - return {"compilation-status": status} + if status is not str: + _status = "No compilation in progress" + _status = status - elif argument == "compilation-logs": try: logs = openplc_runtime.compilation_status() - return {"compilation-logs": logs} + _logs = logs except Exception as e: logger.error(f"Error retrieving compilation logs: {e}") - return {"error": str(e)} + _logs = str(e) + + return {"status": _status, "logs": _logs} elif argument == "status": return {"current_status": "operational", "details": data} @@ -83,6 +84,7 @@ def restapi_callback_get(argument: str, data: dict) -> dict: def restapi_callback_post(argument: str, data: dict) -> dict: logger.debug(f"POST | Received argument: {argument}, data: {data}") + # upload == compile if argument == "upload-file": try: # TODO validate filename, content and size