mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-03 17:55:21 +03:00
Add Save Only button to save config without restarting
This commit is contained in:
parent
19d17c8c81
commit
90aff208fc
@ -762,6 +762,54 @@ def config_save():
|
|||||||
return "Config successfully saved, restarting...", 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
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/config/schema.json")
|
@bp.route("/config/schema.json")
|
||||||
def config_schema():
|
def config_schema():
|
||||||
return current_app.response_class(
|
return current_app.response_class(
|
||||||
|
|||||||
@ -40,6 +40,29 @@ export default function Config() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onHandleSaveConfigOnly = async (e) => {
|
||||||
|
if (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
|
axios
|
||||||
|
.post('config/saveonly', window.editor.getValue(), {
|
||||||
|
headers: { 'Content-Type': 'text/plain' },
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
if (response.status === 200) {
|
||||||
|
setSuccess(response.data);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
if (error.response) {
|
||||||
|
setError(error.response.data.message);
|
||||||
|
} else {
|
||||||
|
setError(error.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleCopyConfig = async () => {
|
const handleCopyConfig = async () => {
|
||||||
copy(window.editor.getValue());
|
copy(window.editor.getValue());
|
||||||
};
|
};
|
||||||
@ -100,6 +123,9 @@ export default function Config() {
|
|||||||
<Button className="mx-2" onClick={(e) => onHandleSaveConfig(e)}>
|
<Button className="mx-2" onClick={(e) => onHandleSaveConfig(e)}>
|
||||||
Save & Restart
|
Save & Restart
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button className="mx-2" onClick={(e) => onHandleSaveConfigOnly(e)}>
|
||||||
|
Save Only
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user