From b28dcf4b5eff173b3911bc855312be707bd6e740 Mon Sep 17 00:00:00 2001 From: yeahme49 Date: Sat, 14 Jan 2023 13:08:34 -0600 Subject: [PATCH] Fixes --- frigate/http.py | 66 +++++++-------------------------------- web/src/routes/Config.jsx | 6 ++-- 2 files changed, 14 insertions(+), 58 deletions(-) diff --git a/frigate/http.py b/frigate/http.py index 1d0d18766..d24f9d130 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -710,6 +710,8 @@ def config_raw(): @bp.route("/config/save", methods=["POST"]) def config_save(): + save_option = request.headers.get('Save-Option') + new_config = request.get_data().decode() if not new_config: @@ -753,62 +755,16 @@ def config_save(): 400, ) - try: - restart_frigate() - except Exception as e: - logging.error(f"Error restarting Frigate: {e}") - return "Config successfully saved, unable to restart Frigate", 200 - - return "Config successfully saved, restarting...", 200 - - -@bp.route("/config/saveonly", methods=["POST"]) -def config_save(): - new_config = request.get_data().decode() - - if not new_config: - return "Config with body param is required", 400 - - # Validate the config schema - try: - new_yaml = FrigateConfig.parse_raw(new_config) - except Exception as e: - return make_response( - jsonify( - { - "success": False, - "message": f"\nConfig Error:\n\n{str(traceback.format_exc())}", - } - ), - 400, - ) - - # Save the config to file - try: - config_file = os.environ.get("CONFIG_FILE", "/config/config.yml") - - # Check if we can use .yaml instead of .yml - config_file_yaml = config_file.replace(".yml", ".yaml") - - if os.path.isfile(config_file_yaml): - config_file = config_file_yaml - - with open(config_file, "w") as f: - f.write(new_config) - f.close() - except Exception as e: - return make_response( - jsonify( - { - "success": False, - "message": f"Could not write config file, be sure that Frigate has write permission on the config file.", - } - ), - 400, - ) - - return "Config successfully saved", 200 + if(save_option == "restart"): + try: + restart_frigate() + except Exception as e: + logging.error(f"Error restarting Frigate: {e}") + return "Config successfully saved, unable to restart Frigate", 200 + return "Config successfully saved, restarting...", 200 + else: + return "Config successfully saved.", 200 @bp.route("/config/schema.json") def config_schema(): diff --git a/web/src/routes/Config.jsx b/web/src/routes/Config.jsx index de07374c7..9348cf04a 100644 --- a/web/src/routes/Config.jsx +++ b/web/src/routes/Config.jsx @@ -24,7 +24,7 @@ export default function Config() { axios .post('config/save', window.editor.getValue(), { - headers: { 'Content-Type': 'text/plain' }, + headers: { 'Content-Type': 'text/plain', 'Save-Option': 'restart' }, }) .then((response) => { if (response.status === 200) { @@ -46,8 +46,8 @@ export default function Config() { } axios - .post('config/saveonly', window.editor.getValue(), { - headers: { 'Content-Type': 'text/plain' }, + .post('config/save', window.editor.getValue(), { + headers: { 'Content-Type': 'text/plain', 'Save-Option': 'saveonly' }, }) .then((response) => { if (response.status === 200) {