update ui

This commit is contained in:
subodh committed 2026-03-08 21:11:43 +05:30
1 parent 0e35933ee3
commit 29280d6490
5 files changed
+207 -454

No files matched your search

+11 -10
View File
@@ -1,5 +1,6 @@
import asyncio
from functools import lru_cache
from typing import BinaryIO
import boto3
from botocore.client import Config
@@ -21,25 +22,25 @@ def _get_r2_client():
)
def _put_object(object_name: str, file_bytes: bytes, content_type: str) -> str:
"""Blocking S3 put"""
def _upload_fileobj(file_obj: BinaryIO, object_name: str, content_type: str) -> str:
"""Stream file to R2. boto3 automatically uses multipart for large files."""
key = f"files/{object_name}"
_get_r2_client().put_object(
Bucket=settings.R2_BUCKET,
Key=key,
Body=file_bytes,
ContentType=content_type,
_get_r2_client().upload_fileobj(
file_obj,
settings.R2_BUCKET,
key,
ExtraArgs={"ContentType": content_type},
)
return f"{settings.PUBLIC_URL}/files/{object_name}"
async def upload_file(file_bytes: bytes, object_name: str, content_type: str) -> str:
"""Upload a file to R2 storage"""
async def upload_file(file_obj: BinaryIO, object_name: str, content_type: str) -> str:
"""Upload a file to R2 storage."""
try:
url = await asyncio.to_thread(
_put_object, object_name, file_bytes, content_type
_upload_fileobj, file_obj, object_name, content_type
)
except (BotoCoreError, ClientError) as exc:
raise RuntimeError(f"R2 upload failed: {exc}") from exc