diff --git a/repeater/storage.py b/repeater/storage.py index 306f679..169c33e 100644 --- a/repeater/storage.py +++ b/repeater/storage.py @@ -207,6 +207,18 @@ class StorageCollector: try: with sqlite3.connect(self.sqlite_path) as conn: + # Ensure fields that are non-sqlite-bindable are serialized + orig_path = record.get("original_path") + fwd_path = record.get("forwarded_path") + try: + orig_path_val = json.dumps(orig_path) if orig_path is not None else None + except Exception: + orig_path_val = str(orig_path) + try: + fwd_path_val = json.dumps(fwd_path) if fwd_path is not None else None + except Exception: + fwd_path_val = str(fwd_path) + conn.execute(""" INSERT INTO packets ( timestamp, type, route, length, rssi, snr, score, @@ -222,8 +234,8 @@ class StorageCollector: record.get("rssi"), record.get("snr"), record.get("score"), - record.get("transmitted", False), - record.get("is_duplicate", False), + int(bool(record.get("transmitted", False))), + int(bool(record.get("is_duplicate", False))), record.get("drop_reason"), record.get("src_hash"), record.get("dst_hash"), @@ -233,8 +245,8 @@ class StorageCollector: record.get("payload_length"), record.get("tx_delay_ms"), record.get("packet_hash"), - record.get("original_path"), - record.get("forwarded_path") + orig_path_val, + fwd_path_val )) except Exception as e: diff --git a/repeater/web/api_endpoints.py b/repeater/web/api_endpoints.py index 1a76e91..101d0de 100644 --- a/repeater/web/api_endpoints.py +++ b/repeater/web/api_endpoints.py @@ -20,9 +20,16 @@ class APIEndpoints: self.cad_calibration = CADCalibrationEngine(daemon_instance, event_loop) def _get_storage(self): - if not self.daemon_instance or not hasattr(self.daemon_instance, 'storage'): - raise Exception("Storage not available") - return self.daemon_instance.storage + if not self.daemon_instance: + raise Exception("Daemon not available") + + if not hasattr(self.daemon_instance, 'repeater_handler') or not self.daemon_instance.repeater_handler: + raise Exception("Repeater handler not initialized") + + if not hasattr(self.daemon_instance.repeater_handler, 'storage') or not self.daemon_instance.repeater_handler.storage: + raise Exception("Storage not initialized in repeater handler") + + return self.daemon_instance.repeater_handler.storage def _success(self, data, **kwargs): result = {"success": True, "data": data}