diff --git a/gui/app.py b/gui/app.py index 9670836..ea13651 100644 --- a/gui/app.py +++ b/gui/app.py @@ -20,7 +20,9 @@ ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "") def db_conn(): - os.makedirs(os.path.dirname(DB_PATH), exist_ok=True) + db_dir = os.path.dirname(DB_PATH) + if db_dir: + os.makedirs(db_dir, exist_ok=True) conn = sqlite3.connect(DB_PATH) conn.row_factory = sqlite3.Row return conn @@ -264,12 +266,15 @@ def new_peer(): with db_conn() as conn: cur = conn.cursor() - cur.execute(""" - INSERT INTO peers(name, public_key, client_address, advertised_routes) - VALUES (?,?,?,?) - ON CONFLICT(public_key) - DO UPDATE SET name=excluded.name, client_address=excluded.client_address, advertised_routes=excluded.advertised_routes - """, (name, client_pub, client_addr, routes)) + cur.execute( + "UPDATE peers SET name=?, client_address=?, advertised_routes=? WHERE public_key=?", + (name, client_addr, routes, client_pub), + ) + if cur.rowcount == 0: + cur.execute( + "INSERT INTO peers(name, public_key, client_address, advertised_routes) VALUES (?,?,?,?)", + (name, client_pub, client_addr, routes), + ) conn.commit() return render_template(