Files
server-26/drb-c2-core/app/internal/storage.py
T
Logan 2f0597c81b Initial commit — DRB server stack
Includes c2-core (FastAPI/MQTT/Firestore), discord-bot (slash commands),
frontend (Next.js admin UI), and mosquitto config.
2026-04-05 19:01:39 -04:00

29 lines
939 B
Python

import asyncio
from typing import Optional
from app.config import settings
from app.internal.logger import logger
async def upload_audio(data: bytes, filename: str) -> Optional[str]:
"""Upload audio bytes to GCS and return the public URL, or None if disabled."""
if not settings.gcs_bucket:
logger.info("GCS_BUCKET not configured — skipping audio upload.")
return None
def _upload() -> str:
from google.cloud import storage
client = storage.Client()
bucket = client.bucket(settings.gcs_bucket)
blob = bucket.blob(f"calls/{filename}")
blob.upload_from_string(data, content_type="audio/mpeg")
blob.make_public()
return blob.public_url
try:
url = await asyncio.to_thread(_upload)
logger.info(f"Audio uploaded: {url}")
return url
except Exception as e:
logger.error(f"GCS upload failed: {e}")
return None