mirror of
https://github.com/thiagoralves/OpenPLC_v3.git
synced 2026-09-26 18:17:45 +08:00
[RTOP-26] Coderabbit nitpick comments review
This commit is contained in:
+2
-1
@@ -11,9 +11,10 @@ class Config:
|
||||
PEPPER = os.getenv("PEPPER")
|
||||
|
||||
class DevConfig(Config):
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = True
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False # keep performance parity with prod
|
||||
DEBUG = True
|
||||
|
||||
class ProdConfig(Config):
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
DEBUG = False
|
||||
ENV = "production"
|
||||
|
||||
@@ -111,7 +111,7 @@ class runtime:
|
||||
|
||||
self.is_compiling = True
|
||||
global compilation_object
|
||||
compilation_status_str = ""
|
||||
self.compilation_status_str = ""
|
||||
|
||||
# Extract debug information from program
|
||||
with open('./st_files/' + st_file, "r") as f:
|
||||
@@ -169,13 +169,12 @@ class runtime:
|
||||
compilation_object = NonBlockingStreamReader(a.stdout)
|
||||
|
||||
def compilation_status(self):
|
||||
global compilation_status_str
|
||||
global compilation_object
|
||||
while compilation_object != None:
|
||||
line = compilation_object.readline()
|
||||
if not line: break
|
||||
compilation_status_str += line
|
||||
return compilation_status_str
|
||||
self.compilation_status_str += line
|
||||
return self.compilation_status_str
|
||||
|
||||
def status(self):
|
||||
if ('compilation_object' in globals()):
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from hmac import compare_digest
|
||||
|
||||
from flask import Flask, Blueprint, jsonify, request
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
@@ -7,7 +5,7 @@ from flask_jwt_extended import create_access_token, current_user, jwt_required,
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
from typing import Callable, Optional
|
||||
import config
|
||||
from . import config
|
||||
|
||||
import os
|
||||
env = os.getenv("FLASK_ENV", "development")
|
||||
@@ -72,9 +70,8 @@ def create_user():
|
||||
users_exist = User.query.first() is not None
|
||||
|
||||
# if there are no users, we don't need to verify JWT
|
||||
if users_exist:
|
||||
if verify_jwt_in_request(optional=True) is None:
|
||||
return jsonify({"msg": "User already created!"}), 401
|
||||
if users_exist and verify_jwt_in_request(optional=True) is None:
|
||||
return jsonify({"msg": "User already created!"}), 401
|
||||
|
||||
data = request.get_json()
|
||||
username = data.get("username")
|
||||
|
||||
+10
-6
@@ -16,6 +16,7 @@ import socket
|
||||
import mimetypes
|
||||
import ssl
|
||||
import threading
|
||||
import logging
|
||||
|
||||
import flask
|
||||
import flask_login
|
||||
@@ -27,6 +28,7 @@ app = flask.Flask(__name__)
|
||||
app.secret_key = str(os.urandom(16))
|
||||
login_manager = flask_login.LoginManager()
|
||||
login_manager.init_app(app)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
openplc_runtime = openplc.runtime()
|
||||
|
||||
@@ -39,8 +41,7 @@ def restapi_callback_get(argument: str, data: dict) -> dict:
|
||||
This is the central callback function that handles the logic
|
||||
based on the 'argument' from the URL and 'data' from the request.
|
||||
"""
|
||||
# TODO logging debug level
|
||||
print(f"GET | Received argument: {argument}, data: {data}")
|
||||
logger.debug(f"GET | Received argument: {argument}, data: {data}")
|
||||
|
||||
if argument == "start-plc":
|
||||
openplc_runtime.start_runtime()
|
||||
@@ -72,8 +73,7 @@ def restapi_callback_get(argument: str, data: dict) -> dict:
|
||||
|
||||
# file upload POST handler
|
||||
def restapi_callback_post(argument: str, data: dict) -> dict:
|
||||
# TODO logging debug level
|
||||
print(f"POST | Received argument: {argument}, data: {data}")
|
||||
logger.debug(f"POST | Received argument: {argument}, data: {data}")
|
||||
|
||||
if argument == "upload-file":
|
||||
try:
|
||||
@@ -2581,8 +2581,12 @@ def run_https():
|
||||
register_callback_post(restapi_callback_post)
|
||||
|
||||
with app_restapi.app_context():
|
||||
db.create_all()
|
||||
db.session.commit()
|
||||
try:
|
||||
db.create_all()
|
||||
db.session.commit()
|
||||
print("Database tables created successfully.")
|
||||
except Exception as e:
|
||||
print(f"Error creating database tables: {e}")
|
||||
|
||||
try:
|
||||
# CertGen class is used to generate SSL certificates and verify their validity
|
||||
|
||||
Reference in New Issue
Block a user