updated buckets for storing audios in supabase
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
SUPABASE_URL=https://tnpnlkosqqudoadfylss.supabase.co
|
||||
SUPABASE_SERVICE_ROLE_KEY=sb_publishable_UqXeuY5gOjvGpoNO1ciZYw_g7nO2M1Q
|
||||
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InRucG5sa29zcXF1ZG9hZGZ5bHNzIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc3MTAyNTQwOCwiZXhwIjoyMDg2NjAxNDA4fQ.v1xblErJBBv8p001vvTCUBfjP8ZqskfXNETB_yJOgvc
|
||||
SUPABASE_BUCKET=archives
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -34,6 +34,7 @@ from db_queries import (
|
||||
list_user_history,
|
||||
search_rag_chunks,
|
||||
update_audio_post,
|
||||
upload_storage_object,
|
||||
upsert_archive_metadata,
|
||||
upsert_archive_rights,
|
||||
)
|
||||
@@ -49,6 +50,7 @@ ALLOWED_MEDIA_EXTENSIONS = {"mp4", "mov", "mkv", "webm", "m4a", "mp3", "wav", "o
|
||||
WHISPER_MODEL = os.getenv("WHISPER_MODEL", "base")
|
||||
WHISPER_DEVICE = os.getenv("WHISPER_DEVICE", "cpu")
|
||||
WHISPER_COMPUTE_TYPE = os.getenv("WHISPER_COMPUTE_TYPE", "int8")
|
||||
ARCHIVE_BUCKET = os.getenv("SUPABASE_BUCKET", os.getenv("SUPABASE_ARCHIVE_BUCKET", "archives"))
|
||||
|
||||
_whisper_model: WhisperModel | None = None
|
||||
|
||||
@@ -207,6 +209,7 @@ def api_upload_post():
|
||||
post_uuid = str(uuid.uuid4())
|
||||
safe_name = secure_filename(media.filename)
|
||||
storage_prefix = f"archive/{user_id}/{post_uuid}"
|
||||
storage_object_path = f"{user_id}/{post_uuid}/original/{safe_name}"
|
||||
saved_path = UPLOAD_DIR / f"{post_uuid}_{safe_name}"
|
||||
media.save(saved_path)
|
||||
|
||||
@@ -226,12 +229,20 @@ def api_upload_post():
|
||||
|
||||
post_id = int(created_post["post_id"])
|
||||
media_sha = _sha256(saved_path)
|
||||
with saved_path.open("rb") as media_file:
|
||||
upload_storage_object(
|
||||
bucket=ARCHIVE_BUCKET,
|
||||
object_path=storage_object_path,
|
||||
content=media_file.read(),
|
||||
content_type=media.mimetype or "application/octet-stream",
|
||||
upsert=False,
|
||||
)
|
||||
|
||||
add_archive_file(
|
||||
post_id,
|
||||
{
|
||||
"role": "original_audio",
|
||||
"path": str(saved_path).replace("\\", "/"),
|
||||
"path": f"{ARCHIVE_BUCKET}/{storage_object_path}",
|
||||
"content_type": media.mimetype,
|
||||
"size_bytes": saved_path.stat().st_size,
|
||||
"sha256": media_sha,
|
||||
@@ -300,7 +311,7 @@ def api_upload_post():
|
||||
"post_id": post_id,
|
||||
"visibility": visibility,
|
||||
"status": "ready",
|
||||
"audio_path": str(saved_path).replace("\\", "/"),
|
||||
"audio_path": f"{ARCHIVE_BUCKET}/{storage_object_path}",
|
||||
"transcript_text": transcript_text,
|
||||
"prompt": prompt_text,
|
||||
"rag_chunk_count": len(rag_rows),
|
||||
|
||||
@@ -36,6 +36,26 @@ def _paginate(page: int, limit: int) -> tuple[int, int]:
|
||||
return start, end
|
||||
|
||||
|
||||
def upload_storage_object(
|
||||
bucket: str,
|
||||
object_path: str,
|
||||
content: bytes,
|
||||
content_type: str = "application/octet-stream",
|
||||
upsert: bool = False,
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Upload bytes to Supabase Storage and return upload response data.
|
||||
"""
|
||||
return (
|
||||
supabase.storage.from_(bucket)
|
||||
.upload(
|
||||
object_path,
|
||||
content,
|
||||
{"content-type": content_type, "upsert": str(upsert).lower()},
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# ==================== Users ====================
|
||||
|
||||
def create_user(payload: Dict[str, Any]) -> Dict[str, Any]:
|
||||
|
||||
BIN
backend/uploads/49fb853c-f424-440a-9414-935862655c7b_data.m4a
Normal file
BIN
backend/uploads/49fb853c-f424-440a-9414-935862655c7b_data.m4a
Normal file
Binary file not shown.
BIN
backend/uploads/502f38f7-18bb-4b43-b09b-d32a0cd4baeb_data.m4a
Normal file
BIN
backend/uploads/502f38f7-18bb-4b43-b09b-d32a0cd4baeb_data.m4a
Normal file
Binary file not shown.
BIN
backend/uploads/61adb8cf-2b50-46d0-8cd8-8079b9f55b35_data.m4a
Normal file
BIN
backend/uploads/61adb8cf-2b50-46d0-8cd8-8079b9f55b35_data.m4a
Normal file
Binary file not shown.
Reference in New Issue
Block a user