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

View File

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