backend api 추가

This commit is contained in:
jaehwang committed 2026-09-08 13:00:23 +09:00
1 parent 2d4201ce9e
commit f008ed4010
15 files changed
+1501 -5

No files matched your search

+25 -3
View File
@@ -40,10 +40,24 @@ def public_url(path: str) -> str:
return f"{settings.azure_blob_base_url.rstrip('/')}/{path.lstrip('/')}"
def upload_url(path: str) -> str:
def sas_token() -> str:
# SAS 토큰이 따옴표나 ? 로 감싸여 오는 경우가 있다
token = settings.azure_blob_sas_token.strip("?'\"")
return f"{public_url(path)}?{token}"
return settings.azure_blob_sas_token.strip("?'\"")
def upload_url(path: str) -> str:
return f"{public_url(path)}?{sas_token()}"
def with_sas(url: str) -> str:
"""컨테이너가 비공개면 읽기에도 토큰이 필요함
우리가 올린 URL일 때만 붙임
"""
token = sas_token()
base = settings.azure_blob_base_url.rstrip("/")
if token and base and url.startswith(base) and "?" not in url:
return f"{url}?{token}"
return url
async def upload_bytes(data: bytes, path: str, content_type: str | None = None) -> str:
@@ -61,3 +75,11 @@ async def upload_bytes(data: bytes, path: str, content_type: str | None = None)
async def upload_file(file_path: Path, path: str, content_type: str | None = None) -> str:
return await upload_bytes(file_path.read_bytes(), path,
content_type or guess_content_type(file_path.name))
async def download_bytes(url: str) -> bytes:
"""upload_bytes가 돌려준 URL을 그대로 받아 내용을 가져온다."""
response = await get_client().get(with_sas(url))
if response.status_code != 200:
raise RuntimeError(f"blob 다운로드 실패 {response.status_code}: {url}")
return response.content