implemented auto updates
This commit is contained in:
+36
-3
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import threading
|
||||
import atexit
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from functools import wraps
|
||||
from pathlib import Path
|
||||
@@ -24,6 +25,7 @@ from db_py import (
|
||||
clear_users,
|
||||
)
|
||||
from scanner import full_scan, is_scan_in_progress, resolve_runtime_path, scan_results_only
|
||||
from watcher import start_results_watchers, stop_results_watchers
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent
|
||||
load_dotenv(BASE_DIR / ".env")
|
||||
@@ -421,6 +423,8 @@ def set_config_route():
|
||||
return jsonify({"error": "Request body must be a JSON object"}), 400
|
||||
|
||||
rescan_required = False
|
||||
watcher_restart_required = False
|
||||
warnings = []
|
||||
|
||||
for key, value in updates.items():
|
||||
if key not in ALLOWED_KEYS:
|
||||
@@ -433,6 +437,19 @@ def set_config_route():
|
||||
|
||||
if key in {"target_dir", "results_dir", "results_dir_ref", "scan_exclusions"}:
|
||||
rescan_required = True
|
||||
if key in {"results_dir", "results_dir_ref", "smb_username", "smb_password", "smb_domain"}:
|
||||
watcher_restart_required = True
|
||||
|
||||
if watcher_restart_required:
|
||||
_apply_smb_env_from_config()
|
||||
results_dir = resolve_runtime_path(get_config("results_dir"))
|
||||
results_dir_ref = resolve_runtime_path(get_config("results_dir_ref"))
|
||||
try:
|
||||
start_results_watchers(results_dir, results_dir_ref)
|
||||
except Exception as exc:
|
||||
warning = f"Watcher restart failed: {exc}"
|
||||
warnings.append(warning)
|
||||
print(f"[server] {warning}")
|
||||
|
||||
if rescan_required:
|
||||
_apply_smb_env_from_config()
|
||||
@@ -443,16 +460,28 @@ def set_config_route():
|
||||
return jsonify({"error": "Directories not configured"}), 400
|
||||
|
||||
if is_scan_in_progress():
|
||||
return jsonify({"ok": True, "scanning": True, "testCount": None, "completedCount": None})
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
"scanning": True,
|
||||
"testCount": None,
|
||||
"completedCount": None,
|
||||
"warnings": warnings,
|
||||
})
|
||||
|
||||
threading.Thread(
|
||||
target=full_scan,
|
||||
args=(target_dir, results_dir, results_dir_ref),
|
||||
daemon=True,
|
||||
).start()
|
||||
return jsonify({"ok": True, "scanning": True, "testCount": None, "completedCount": None})
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
"scanning": True,
|
||||
"testCount": None,
|
||||
"completedCount": None,
|
||||
"warnings": warnings,
|
||||
})
|
||||
|
||||
return jsonify({"ok": True, "testCount": None, "completedCount": None})
|
||||
return jsonify({"ok": True, "testCount": None, "completedCount": None, "warnings": warnings})
|
||||
|
||||
|
||||
@app.post("/api/config/rescan")
|
||||
@@ -526,11 +555,15 @@ def bootstrap():
|
||||
tests = get_all_tests()
|
||||
completed = len([t for t in tests if t.get("completed")])
|
||||
print(f"[server] Scan complete -> {len(tests)} tests found, {completed} completed")
|
||||
|
||||
start_results_watchers(results_dir, results_dir_ref)
|
||||
else:
|
||||
stop_results_watchers()
|
||||
print("[server] No directories configured -> open the dashboard settings to get started.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
atexit.register(stop_results_watchers)
|
||||
bootstrap()
|
||||
print(f"[server] Listening on http://0.0.0.0:{PORT}")
|
||||
app.run(host="0.0.0.0", port=PORT, threaded=True)
|
||||
|
||||
Reference in New Issue
Block a user