Move bucket upload to the c2 server and replaced with upload to c2 server
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@
|
|||||||
*.db
|
*.db
|
||||||
*.conf
|
*.conf
|
||||||
configs/*
|
configs/*
|
||||||
|
*.json
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -4,4 +4,3 @@ paho-mqtt
|
|||||||
pydantic
|
pydantic
|
||||||
python-multipart
|
python-multipart
|
||||||
requests
|
requests
|
||||||
google-cloud-storage
|
|
||||||
Reference in New Issue
Block a user