Move bucket upload to the c2 server and replaced with upload to c2 server

This commit is contained in:
Logan Cusano
2025-12-30 03:01:31 -05:00
parent a5d5fa9de7
commit 8c106473cf
3 changed files with 9 additions and 11 deletions

3
.gitignore vendored
View File

@@ -2,4 +2,5 @@
*.log *.log
*.db *.db
*.conf *.conf
configs/* configs/*
*.json

View File

@@ -9,7 +9,6 @@ from internal.logger import create_logger
from internal.op25_config_utls import scan_local_library from internal.op25_config_utls import scan_local_library
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import requests import requests
from google.cloud import storage
# Initialize logging # Initialize logging
LOGGER = create_logger(__name__) LOGGER = create_logger(__name__)
@@ -23,7 +22,6 @@ NODE_ID = os.getenv("NODE_ID", "standalone-node")
MQTT_BROKER = os.getenv("MQTT_BROKER", None) MQTT_BROKER = os.getenv("MQTT_BROKER", None)
NODE_LAT = os.getenv("NODE_LAT") NODE_LAT = os.getenv("NODE_LAT")
NODE_LONG = os.getenv("NODE_LONG") NODE_LONG = os.getenv("NODE_LONG")
AUDIO_BUCKET = os.getenv("AUDIO_BUCKET")
# Global flag to track MQTT connection state # Global flag to track MQTT connection state
MQTT_CONNECTED = False MQTT_CONNECTED = False
@@ -246,16 +244,16 @@ async def mqtt_lifecycle_manager():
recorder_proc = None recorder_proc = None
def upload_audio(call_id): def upload_audio(call_id):
if not AUDIO_BUCKET: return None if not MQTT_BROKER: return None
local_path = f"/calls/{call_id}.mp3" local_path = f"/calls/{call_id}.mp3"
if not os.path.exists(local_path): return None if not os.path.exists(local_path): return None
try: try:
client = storage.Client() with open(local_path, "rb") as f:
bucket = client.bucket(AUDIO_BUCKET) files = {"file": (f"{call_id}.mp3", f, "audio/mpeg")}
blob = bucket.blob(f"audio/{call_id}.mp3") response = requests.post(f"{MQTT_BROKER}/upload", files=files, data={"node_id": NODE_ID, "call_id": call_id}, timeout=30)
blob.upload_from_filename(local_path, content_type="audio/mpeg") response.raise_for_status()
return f"gs://{AUDIO_BUCKET}/audio/{call_id}.mp3" return response.json().get("url")
except Exception as e: except Exception as e:
LOGGER.error(f"Upload failed: {e}") LOGGER.error(f"Upload failed: {e}")
return None return None

View File

@@ -3,5 +3,4 @@ uvicorn[standard]
paho-mqtt paho-mqtt
pydantic pydantic
python-multipart python-multipart
requests requests
google-cloud-storage